So I’m attempting to generate a 4×4 where the bottom left is a perfect square.
fig=plt.figure()
ax=np.empty((2,2,),dtype=object)
ax[1][0]=fig.add_subplot(2,2,3)
ax[0][0]=fig.add_subplot(2,2,1,sharex=ax[1][0])
ax[1][1]=fig.add_subplot(2,2,4,sharey=ax[1][0])
ax[0][1]=fig.add_subplot(2,2,2,sharex=ax[1][1],sharey=ax[0][0])
plt.subplots_adjust(hspace=0,wspace=0)
old_position,old_position2,old_position3,old_position4=list(ax[0][0].get_position().bounds),list(ax[1][1].get_position().bounds),list(ax[1][0].get_position().bounds),list(ax[0][1].get_position().bounds)
old_position[-1]=old_position[-1]/2
old_position2[-2]=old_position2[-2]/2
old_position3[-1]=old_position3[-2]
old_position4[-1]=old_position4[-1]/2
old_position4[-2]=old_position4[-2]/2
ax[0][0].set_position(old_position)
ax[1][1].set_position(old_position2)
ax[1][0].set_position(old_position3)
ax[0][1].set_position(old_position4)
ax[0][0].xaxis.set_visible(False)
ax[0][1].xaxis.set_visible(False)
ax[1][1].yaxis.set_visible(False)
ax[0][1].yaxis.set_visible(False)
#plot stuff onto axes objects
plt.suptitle('Test')
plt.show()
So this should mean that the bottom left plot ([1][0]) should be a perfect square, since old_position3[-1]=[-2]
, in fact looking at old_position3, you get [0.125, 0.10999999999999999, 0.38749999999999996, 0.38749999999999996]
, so the x,y dimensions are both the same 0.3874
.
However, upon plotting/display, these dimensions are not perfect for the bottom left. The ratio of height/width is about 3/5in, and I don’t quite understand why. Furthermore, why is the title (suptitle) using the old dimensions (it’s situated high above).
>Solution :
To get a square bottom left figure, just provide a square figsize
at creation:
fig = plt.figure(figsize=(10, 10))
The default figsize is 6.4 by 4.8 (source).
The title is therefore not centered as you changed the axes coordinates without changing the figure size. More info here.