开发者

Is there a way to tell matplotlib to loosen the zoom on the plotted data? [duplicate]

开发者 https://www.devze.com 2023-03-10 11:04 出处:网络
This question already has an answer here: Add margin when plots run against the edge of the graph (1 answer)
This question already has an answer here: Add margin when plots run against the edge of the graph (1 answer) Closed 8 years ago.

I have some data plotted which includes some limits on each subplot:

Is there a way to tell matplotlib to loosen the zoom on the plotted data? [duplicate]

Both axes have the limits, but since the data fits so nicely within the limits on the second plot, the limits themselves set the boudaries for the y-axis, making them invisible.

To make them visible, I could do something like this:

axes.set_ylim(1.1*lowerLimit,1.1*upperLimit)

where lowerLimit and upperLimit are the data used to generate the limits in the first place, but I am wondering if matplotlib has a mechanism to tell it to not be so zealous in it's automatic setting of the limits. The solution I have now also has the limitation that if the data deviates from the boundaries, it risks going outside the lines, so I searched for a complement to set_ylim() which would tell me what the limits are, somehting like 开发者_如何学Pythonget_ylim() but it does not seem to exist in the documentation.

Thanks for your help.


In regards to your request for a function to change the y-axis limits, would this suit your purposes?:

def larger_axlim( axlim ):
    """ argument axlim expects 2-tuple 
        returns slightly larger 2-tuple """
    axmin,axmax = axlim
    axrng = axmax - axmin
    new_min = axmin - 0.1 * axrng
    new_max = axmax + 0.1 * axrng
    return new_min,new_max
...
ax.set_ylim( larger_axlim( ax.get_ylim() ) )
...

Documentation: get_ylim()

0

精彩评论

暂无评论...
验证码 换一张
取 消