Matplotlib.axes.Axes.get_axisbelow() in Python - GeeksforGeeks

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.
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 functionimport matplotlib.pyplot as pltimport numpy as np  # Random test datanp.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 functionimport matplotlib.pyplot as pltimport numpy as np  # Random test datanp.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:
Python-matplotlib
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to Install PIP on Windows ?
Check if element exists in list in Python
How To Convert Python Dictionary To JSON?
Python Classes and Objects
How to drop one or multiple columns in Pandas Dataframe
Defaultdict in Python
Python | Get unique values from a list
Python | os.path.join() method
Create a directory in Python
Python | Pandas dataframe.groupby()