Matplotlib子图y轴刻度与上面的图重叠

Matplotlib子图y轴刻度与上面的图重叠,第1张

Matplotlib子图y轴刻度与上面的图重叠

我有两个选项您可能要看看。

首先,这样设置轴的位置和大小:

# your imports and data abovefig = plt.figure()ax0a = fig.add_axes([0.1, 0.1, 0.8, 0.25])ax0b = fig.add_axes([0.1, 0.39, 0.8, 0.25], sharex=ax0a)ax0c = fig.add_axes([0.1, 0.68, 0.8, 0.25], sharex=ax0a)ax0a.set_xticklabels([])ax0b.set_xticklabels([]) ax0a.plot(x,y)nbins = len(ax0a.get_xticklabels())ax0a.yaxis.set_major_locator(MaxNLocator(nbins=nbins, prune='upper'))ax0b.plot(x,y)ax0b.yaxis.set_major_locator(MaxNLocator(nbins=nbins, prune='upper'))ax0c.plot(x,y)ax0c.yaxis.set_major_locator(MaxNLocator(nbins=nbins, prune='upper'))plt.show()

第二个选项是手动调整偏移文本的位置以及字体大小:

# your original pre minus data and importsfig = plt.figure()gs1 = gridspec.GridSpec(3, 3)gs1.update(left=0.1, right=0.9, bottom=0.5, hspace=0.0)ax0a = plt.subplot(gs1[0, :])ax0b = plt.subplot(gs1[1, :])ax0c = plt.subplot(gs1[2, :])ax0a.set_xticklabels([])ax0b.set_xticklabels([]) ax0a.plot(x,y)nbins = len(ax0a.get_xticklabels())ax0a.yaxis.set_major_locator(MaxNLocator(nbins=nbins, prune='upper'))ax0b.plot(x,y)ax0b.yaxis.set_major_locator(MaxNLocator(nbins=nbins, prune='upper'))ax0c.plot(x,y)ax0c.yaxis.set_major_locator(MaxNLocator(nbins=nbins, prune='upper'))# play around with location and font of offset text hereax0a.get_yaxis().get_offset_text().set_x(-0.075)ax0a.get_yaxis().get_offset_text().set_size(10)ax0b.get_yaxis().get_offset_text().set_x(-0.075)ax0b.get_yaxis().get_offset_text().set_size(10)ax0c.get_yaxis().get_offset_text().set_x(-0.075)ax0c.get_yaxis().get_offset_text().set_size(10)plt.show()



欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5631692.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-15

发表评论

登录后才能评论

评论列表(0条)

保存