Matplotlib.axes.Axes.get_autoscale_on() in Python
Last Updated :
19 Apr, 2020
Matplotlib is a library in Python and it is numerical – mathematical extension for NumPy library. The Axes Class contains most of the figure elements: Axis, Tick, Line2D, Text, Polygon, etc., and sets the coordinate system. And the instances of Axes supports callbacks through a callbacks attribute.
matplotlib.axes.Axes.get_autoscale_on() Function
The Axes.get_autoscale_on() function in axes module of matplotlib library is used to get whether autoscaling is applied for both axes on plot commands.
Syntax: Axes.get_autoscale_on(self)
Parameters: This method does not accepts any parameters.
Return value: This method returns the boolean value.
Below examples illustrate the matplotlib.axes.Axes.get_autoscale_on() function in matplotlib.axes:
Example 1:
import numpy as np
import matplotlib.pyplot as plt
xdata = np.linspace( 16 , 365 , 300 )
ydata = np.sin( 2 * np.pi * xdata / 15 ) + np.cos( 2 * np.pi * xdata / 17 )
fig, ax = plt.subplots()
ax.plot(xdata, ydata, 'g-' )
w = ax.get_autoscale_on()
ax.text( 75 , 1.95 , "Value return by get_autoscale_on : "
+ str (w), fontweight = "bold" )
fig.suptitle('matplotlib.axes.Axes.get_autoscale_on() \
function Example\n', fontweight = "bold" )
fig.canvas.draw()
plt.show()
|
Output:
Example 2:
import numpy as np
import matplotlib.pyplot as plt
xdata = np.linspace( 16 , 365 , ( 365 - 16 ))
ydata = np.sin( 2 * np.pi * xdata / 50 ) + np.cos( 2 * np.pi * xdata / 20 )
fig, (ax, ax1) = plt.subplots( 1 , 2 )
ax.plot(xdata, ydata, 'g-' , alpha = 0.4 )
ax.set_title( "Axes 1" )
ax1.plot(xdata, ydata, 'g-' )
ax1.set_autoscale_on( False )
ax1.set_title( "Axes 2" )
w = ax.get_autoscale_on()
ax.text( 75 , 0 , "Value return : " + str (w),
fontweight = "bold" )
w1 = ax1.get_autoscale_on()
ax1.text( 0.2 , 0.5 , "Value return : " + str (w1),
fontweight = "bold" )
fig.suptitle('matplotlib.axes.Axes.get_autoscale_on()\
function Example\n', fontweight = "bold" )
fig.canvas.draw()
plt.show()
|
Output:
Share your thoughts in the comments
Please Login to comment...