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

Matplotlib subplots_adjust hspace以便标题和xlabel不重叠?

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

Matplotlib subplots_adjust hspace以便标题和xlabel不重叠?

我觉得这很棘手,但是MatPlotLib常见问题解答上有一些有关此方面的信息。这很麻烦,并且需要找出各个元素(刻度标签)占用的空间…

更新: 该页面指出该

tight_layout()
功能是最简单的方法,它会尝试自动更正间距。

否则,它显示了获取各种元素(例如标签)大小的方法,因此您可以更正轴元素的间距/位置。这是上述FAQ页面中的示例,该示例确定非常宽的y轴标签的宽度,并相应地调整轴宽度:

import matplotlib.pyplot as pltimport matplotlib.transforms as mtransformsfig = plt.figure()ax = fig.add_subplot(111)ax.plot(range(10))ax.set_yticks((2,5,7))labels = ax.set_yticklabels(('really, really, really', 'long', 'labels'))def on_draw(event):   bboxes = []   for label in labels:       bbox = label.get_window_extent()       # the figure transform goes from relative coords->pixels and we       # want the inverse of that       bboxi = bbox.inverse_transformed(fig.transFigure)       bboxes.append(bboxi)   # this is the bbox that bounds all the bboxes, again in relative   # figure coords   bbox = mtransforms.Bbox.union(bboxes)   if fig.subplotpars.left < bbox.width:       # we need to move it over       fig.subplots_adjust(left=1.1*bbox.width) # pad a little       fig.canvas.draw()   return Falsefig.canvas.mpl_connect('draw_event', on_draw)plt.show()


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

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

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