Is there a way to tell matplotlib to loosen the zoom on the plotted data? [duplicate]
I have some data plotted which includes some limits on each subplot:
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()
精彩评论