在下面的示例中,如何让ax2(底部)占用左侧的全部空间?
我所说的“占用全部空间”是指将绘图区域扩展到图形的左侧限制,即使用标签标题下方的空白和ax1中的刻度。在
import matplotlib.gridspec as gridspec
import matplotlib.pyplot as plt
def example_plot(ax, fontsize=12):
ax.plot([1, 2])
ax.locator_params(nbins=3)
ax.set_xlabel('x-label', fontsize=fontsize)
ax.set_ylabel('y-label', fontsize=fontsize)
ax.set_title('Title', fontsize=fontsize)
def example_plot_noY(ax, fontsize=12):
ax.plot([1, 2])
ax.locator_params(nbins=3)
ax.set_xlabel('x-label', fontsize=fontsize)
ax.set_yticks([])
ax.set_title('Title', fontsize=fontsize)
plt.close('all')
fig = plt.figure()
gs1 = gridspec.GridSpec(2, 1)
ax1 = fig.add_subplot(gs1[0])
ax2 = fig.add_subplot(gs1[1])
example_plot(ax1)
example_plot_noY(ax2)
gs1.tight_layout(fig)
plt.show()
见GridSpec with Varying Cell Sizes。 可以在gridspec中添加另一列,该列将占用上部绘图的标签空间。如果你后来调用紧凑布局,你不需要关心它的宽度,它可以是0大小
相关问题 更多 >
编程相关推荐