Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Matplotlib and iPython, How to reset x and y axis limits to Autoscale?

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.

like image 790
DJElbow Avatar asked Sep 13 '13 21:09

DJElbow


People also ask

How do I change the X and Y scale in MatPlotLib?

MatPlotLib with Python To change the range of X and Y axes, we can use xlim() and ylim() methods.

How do you autoscale a plot in Python?

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.


1 Answers

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
like image 116
tacaswell Avatar answered Oct 18 '22 11:10

tacaswell