2015-03-31 18 views
1

类似的问题在这里 Autoscale with margin in matplotlib的Python:添加X-Y利润率与自动缩放(pyplot)自动

enter image description here

问,所以我不喜欢的事实,数字和柱状图的外框触摸对方。给出的解决方案是:

axes.set_ylim(0, 11) 

好,它的工作原理,但我有很多的数字,每一次我只想要一个10%的保证金。所以手动这是一件很困难的事情,有没有办法在x轴和y轴上设置边距?

我需要类似subplots_adjust,但对于内部数据区域。

回答

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