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.set_axis_on() Function
The Axes.set_axis_on() function in axes module of matplotlib library is used to turn the x- and y-axis on and this affects the axis lines, ticks, ticklabels, grid and axis labels.
Syntax: Axes.set_axis_on(self)
Parameters: This method does not accept any parameters.
Returns:This method does not returns anything.
Note: This function works only when set_axis_off function is used previously.
Below examples illustrate the matplotlib.axes.Axes.set_axis_on() function in matplotlib.axes:
Example 1:
# Implementation of matplotlib function import matplotlib.pyplot as plt import numpy as np Ā Ā Ā Ā Ā # Time series data neveropenx = np.array([ 24.40 , 110.25 , 20.05 , Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā 22.00 , 61.90 , 7.80 ,Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā 15.00 ]) Ā Ā neveropeny = np.array([ 24.40 , 110.25 , 20.05 , Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā 22.00 , 61.90 , 7.80 , Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā 15.00 ]) Ā Ā Ā Ā Ā fig, ax = plt.subplots() ax.xcorr(neveropenx,Ā neveropeny, maxlags = 6 ,Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā color = "green" ) Ā Ā Ā ax.set_axis_off() ax.set_axis_on() ax.set_title('matplotlib.axes.Axes.set_axis_on() \ Example') plt.show() |
Output:
Example 2:
# Implementation of matplotlib function import matplotlib.pyplot as plt import matplotlib.tri as mtri import numpy as np Ā Ā Ā Ā Ā x = np.asarray([ 0 , 1 , 2 , 3 , 0.5 , Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā 1.5 , 2.5 , 1 , 2 , Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā 1.5 ]) y = np.asarray([ 0 , 0 , 0 , 0 , 1.0 , Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā 1.0 , 1.0 , 2 , 2 , Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā 3.0 ]) Ā Ā triangles = [[ 0 , 1 , 4 ], [ 1 , 5 , 4 ],Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā [ 2 , 6 , 5 ], [ 4 , 5 , 7 ], Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā [ 5 , 6 , 8 ], [ 5 , 8 , 7 ],Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā [ 7 , 8 , 9 ], [ 1 , 2 , 5 ],Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā [ 2 , 3 , 6 ]] Ā Ā triang = mtri.Triangulation(x, y, triangles) z = np.cos( 1.5 * x) * np.cos( 1.5 * y) Ā Ā Ā Ā Ā fig, [axs, axs1] = plt.subplots( 1 , 2 ) axs.tricontourf(triang, z) axs.triplot(triang, 'go-' , color = 'white' ) axs.set_axis_off() axs.set_title( 'Without set_axis_on' ,Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā fontsize = 10 ,Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā fontweight = 'bold' ) Ā Ā axs1.tricontourf(triang, z) axs1.triplot(triang, 'go-' , color = 'white' ) axs1.set_xlabel( "X-axis" ) axs1.set_ylabel( "Y-axis" ) axs1.set_axis_off() Ā Ā axs1.set_axis_on() axs1.set_title( 'With set_axis_on ' , Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā fontsize = 10 , Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā fontweight = 'bold' ) Ā Ā plt.show() |
Output: