Python: 使用自动缩放自动添加 x-y 边距 (pyplot)
Python: Add x-y margins automatically with autoscale (pyplot)
这里问了一个类似的问题
Autoscale with margin in matplotlib
所以我不喜欢图形的框架和直方图条相互接触的事实。给出的解决方案是:
axes.set_ylim(0, 11)
很好,有效,但我有很多数字,每次我只想要 10% 的保证金。所以手动是一件很困难的事情,有没有办法在x轴和y轴上都设置边距?
我需要类似 subplots_adjust
的内容,但用于内部数据区域。
不确定是否有办法使用 matplotlib 函数执行此操作,但您始终可以定义自己的函数,以下对我有用:
def inner_subplots_adjust(axes, xmargin=0.1, ymargin = 0.1):
xmin, xmax = axes.get_xbound()
ymin, ymax = axes.get_ybound()
xscale = 1 + xmargin
yscale = 1 + ymargin
axes.set_xbound((xmin*xscale, xmax*xscale))
axes.set_ybound((ymin*yscale, ymax*yscale))
这里问了一个类似的问题 Autoscale with margin in matplotlib
所以我不喜欢图形的框架和直方图条相互接触的事实。给出的解决方案是:
axes.set_ylim(0, 11)
很好,有效,但我有很多数字,每次我只想要 10% 的保证金。所以手动是一件很困难的事情,有没有办法在x轴和y轴上都设置边距?
我需要类似 subplots_adjust
的内容,但用于内部数据区域。
不确定是否有办法使用 matplotlib 函数执行此操作,但您始终可以定义自己的函数,以下对我有用:
def inner_subplots_adjust(axes, xmargin=0.1, ymargin = 0.1):
xmin, xmax = axes.get_xbound()
ymin, ymax = axes.get_ybound()
xscale = 1 + xmargin
yscale = 1 + ymargin
axes.set_xbound((xmin*xscale, xmax*xscale))
axes.set_ybound((ymin*yscale, ymax*yscale))