Sunday, November 17, 2024
Google search engine
HomeLanguagesMatplotlib.axes.Axes.set_axis_on() in Python

Matplotlib.axes.Axes.set_axis_on() in Python

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:

Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments