这里也有类似的问题 Autoscale with margin in matplotlib
因此我不喜欢图形和直方图条纹相互接触的事实。给出的解决方案是:
axes.set_ylim(0, 11)
好,它有效,但我有很多数字,每次我只想要10%的保证金。所以手动这是一件困难的事情,有没有办法在x轴和y轴上设置边距?
我需要类似subplots_adjust
的东西,但需要内部数据区。
答案 0 :(得分:3)
不确定是否有办法使用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))