栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

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

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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()



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/625806.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号