Skip to content
Related Articles

Related Articles

Matplotlib.figure.Figure.get_axes() in Python

View Discussion
Improve Article
Save Article
Like Article
  • Last Updated : 30 Apr, 2020

Matplotlib is a library in Python and it is numerical – mathematical extension for NumPy library. The figure module provides the top-level Artist, the Figure, which contains all the plot elements. This module is used to control the default spacing of the subplots and top level container for all plot elements.

matplotlib.figure.Figure.get_axes() method

The get_axes() method figure module of matplotlib library is used to get the list of axes in the Figure.

Syntax: get_axes(self)

Parameters: This method does not accept any parameters.

Returns: This method returns a list of axes in the Figure.

Below examples illustrate the matplotlib.figure.Figure.get_axes() function in matplotlib.figure:

Example 1:




# Implementation of matplotlib function
import matplotlib.pyplot as plt
from matplotlib.tri import Triangulation
from matplotlib.patches import Polygon
import numpy as np
  
  
xs = list([ 1, 2, 3, 4, 5, 6, 7, 8, 9])
ys = list([9, 8, 7, 6, 5, 4, 3, 2, 1])
          
fig = plt.figure()
  
ax = fig.add_subplot(111)
ax.plot(ys, xs)
  
fig.get_axes()[0].set_ylabel("Y label")
fig.get_axes()[0].set_xlabel("X label")
  
  
fig.suptitle('matplotlib.figure.Figure.get_axes()\
function Example\n\n', fontweight ="bold")
  
plt.show()

Output:

Example 2:




# Implementation of matplotlib function
import matplotlib.pyplot as plt
from matplotlib.tri import Triangulation
from matplotlib.patches import Polygon
import numpy as np
  
  
xs = list([ 1, 2, 3, 4, 5, 6, 7, 8, 9])
ys = list([9, 8, 7, 6, 5, 4, 3, 2, 1])
          
fig = plt.figure()
  
ax = fig.add_subplot(111)
ax.bar(ys, xs, width = 0.5, align ="center")
  
fig.get_axes()[0].set_ylabel("Number")
fig.get_axes()[0].set_xlabel("Values")
  
  
fig.suptitle('matplotlib.figure.Figure.get_axes()\
 function Example\n\n', fontweight ="bold")
  
plt.show()

Output:


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!