Using matplotlib and iPython, I have a bunch of plots that I am trying to view (one after the other). Some plots only contain values from 0 to 1 and some contain values in the millions.
After setting the y axis limits using:
ylim((.7,1))
I want to be able to reset this to set the limits automatically (as it would have done before). I am having trouble finding the correct approach.
MatPlotLib with Python To change the range of X and Y axes, we can use xlim() and ylim() methods.
autoscale() is a method for simple axis view autoscaling. It turns autoscaling on or off, and then, if autoscaling for either axis is on, it performs the autoscaling on the specified axis or axes. Parameters: enable is a Boolean valued parameter, if it is set to True the autoscaling is on else auto-scaling is off.
ax = plt.gca() # get the current axes
ax.relim() # make sure all the data fits
ax.autoscale() # auto-scale
# only needed mpl < 1.5
# ax.figure.canvas.draw_idle() # re-draw the figure
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With