如何在python中使我的2x2子图为正方形

如何在python中使我的2x2子图为正方形,python,matplotlib,subplot,Python,Matplotlib,Subplot,我需要使这些2x2子地块成为正方形,同时仍然让它们共享同一轴,并且不改变轴边界。我真的不想移动我的图例或改变我的轴范围,如果我不需要的话 这是我的密码: fig, ((ax1, ax2), (ax3, ax4)) = plt.pyplot.subplots(2, 2, sharex = True) fig.subplots_adjust(hspace=0, wspace = 0) plt.pyplot.subplots_adjust(right=.8, top=.8) ax1.grid() ax

我需要使这些2x2子地块成为正方形,同时仍然让它们共享同一轴,并且不改变轴边界。我真的不想移动我的图例或改变我的轴范围,如果我不需要的话

这是我的密码:

fig, ((ax1, ax2), (ax3, ax4)) = plt.pyplot.subplots(2, 2, sharex = True)
fig.subplots_adjust(hspace=0, wspace = 0)
plt.pyplot.subplots_adjust(right=.8, top=.8)
ax1.grid()
ax2.grid()
ax3.grid()
ax4.grid()
ax1.scatter(p1, q1, marker = 's', color = 'royalblue', alpha = 0.5, label = 'Saintonage et al. 2017')
ax1.scatter(p33, q33, marker = 's', color = 'rebeccapurple', alpha = 0.5)
ax3.grid()
ax1.plot(x000, func6(x000), color ='k')
ax1.xaxis.grid(True, which='minor')
ax2.xaxis.grid(True, which='minor')
ax3.xaxis.grid(True, which='minor')
ax4.xaxis.grid(True, which='minor')
ax1.scatter(p2, q2, marker = 's', color = 'seagreen', alpha = 0.5, label = 'Saintonage et al. 2017')
ax1.scatter(p3, q3, marker ='s', color = 'maroon', alpha = 0.5, label = 'Saintonage et al. 2017')
ax1.set_ylim([-1.2, 2.2])
ax2.scatter(p4, q4, marker = 'o', color = 'royalblue', alpha = 0.75)
ax2.scatter(p30, q30, marker = 'o', color = 'rebeccapurple', alpha = 0.75)
ax2.plot(x0, func1(x0), color ='k')
ax2.scatter(p5, q5, marker = 'o', color = 'seagreen', alpha = 0.75)
ax2.set_ylim([-1.2, 2.2])
ax2.set_xlim([9.8, 11.7])
ax3.scatter(p7, q7, marker = 'D', color = 'royalblue', alpha = 0.75)
ax3.plot(x00, func2(x00), color = 'k')
upperlimit = np.array([1], dtype = bool)
ax4.scatter(lmassg, lsfrg, marker = 'd', color = 'maroon')  
ax3.set_ylim([0, 3.5])
ax4.plot(x000, func(x000), color ='k')
ax4.set_ylim([0, 3.5])
fig.legend(handles = legend_elements, numpoints = 1, loc = (.77, .3), ncol=1, fontsize = 8 )
ax1.tick_params(axis='both', labelsize=10)
ax1.tick_params(axis='both', labelsize=12)
ax2.tick_params(axis='both', labelsize=10)
ax2.tick_params(axis='both',  labelsize=2)
ax3.tick_params(axis='both', labelsize=12)
ax3.tick_params(axis='both', labelsize=12)
ax4.tick_params(axis='both', labelsize=12)
ax4.tick_params(axis='y', labelsize=2)
以下是我的情节:

这将在将来使用中变得容易得多。但现在,您必须使用axes_grid1工具包,或者在需要方形子地块的约束下计算所需的子地块参数(左、右、下、上)。对于后者,您基本上有
figwidth*(右左)=2*axsize
figheight*(上下)=2*axsize
。所以
figwdth/figheight=(上下)/(右左)
。设置值,使此方程成立。