Open In App

Matplotlib.axes.Axes.get_axisbelow() in Python

Improve
Improve
Like Article
Like
Save
Share
Report

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_axisbelow() Function

The Axes.get_axisbelow() function in axes module of matplotlib library is used to get whether axis ticks and gridlines are above or below most artists.

Syntax: Axes.get_axisbelow(self)

Parameters: This method does not accept any parameters.

Returns:This method return axisbelow . This is the value through which we get whether the axis ticks and gridlines are above or below most artists.

Below examples illustrate the matplotlib.axes.Axes.get_axisbelow() function in matplotlib.axes:

Example 1:




# Implementation of matplotlib function
import matplotlib.pyplot as plt
import numpy as np
  
# Random test data
np.random.seed(19680801)
all_data = [np.random.normal(0, std, size = 100) for std in range(1, 6)]
labels = ['x1', 'x2', 'x3', 'x4', 'x5']
  
fig, ax = plt.subplots()
  
bplot = ax.boxplot(all_data,
                     vert = True,  
                     patch_artist = True,  
                     labels = labels) 
colors = ['lightpink', 'lightblue', 'lightgreen'
          "lightgrey", "yellow"]
  
for patch, color in zip(bplot['boxes'], colors):
    patch.set_facecolor(color)
  
ax.yaxis.grid(True, color ="green", lw = 2)
ax.set_axisbelow(True)
ax.set_xlabel('Samples')
ax.set_ylabel('Observed values')
x = ax.get_axisbelow()
ax.text(2, 15.7, "Result of get_axisbelow : " +str(x),
        style ='italic', fontsize = 12, color ="green")
  
ax.set_title('matplotlib.axes.Axes.get_axisbelow() \
Example\n\n', fontsize = 12, fontweight ='bold')
plt.show()


Output:

Example 2:




# Implementation of matplotlib function
import matplotlib.pyplot as plt
import numpy as np
  
# Random test data
np.random.seed(19680801)
all_data = [np.random.normal(0, std, size = 100) for std in range(1, 6)]
labels = ['x1', 'x2', 'x3', 'x4', 'x5']
  
fig, ax = plt.subplots()
  
bplot = ax.boxplot(all_data,
                     vert = True,  
                     patch_artist = True,  
                     labels = labels) 
colors = ['lightpink', 'lightblue', 'lightgreen',
          "lightgrey", "yellow"]
for patch, color in zip(bplot['boxes'], colors):
    patch.set_facecolor(color)
  
ax.yaxis.grid(True, color ="green", lw = 2)
ax.set_axisbelow(False)
ax.set_xlabel('Samples')
ax.set_ylabel('Observed values')
x = ax.get_axisbelow()
ax.text(2, 15.7, "Result of get_axisbelow : " +str(x), 
       style ='italic', fontsize = 12, color ="green")
  
ax.set_title('matplotlib.axes.Axes.get_axisbelow() \
Example\n\n', fontsize = 12, fontweight ='bold')
plt.show()


Output:



Last Updated : 19 Apr, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads