Friday, September 26, 2025
HomeLanguagesMatplotlib.axes.Axes.findobj() in Python

Matplotlib.axes.Axes.findobj() 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.findobj() Function

The Axes.findobj() function in axes module of matplotlib library is used to find artist objects.

Syntax: Axes.findobj(self, match=None, include_self=True)

Parameters: This method accepts the following parameters.

  • match : This parameter is the filter criterion for the matches. It default value is None.
  • include_self : This parameter include self in the list to be checked for a match.

Returns: This method return artists(list of Artist).

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

Example 1:




# Implementation of matplotlib function
import matplotlib.pyplot as plt
from matplotlib.lines import Line2D
import numpy as np
from numpy.random import rand
    
  
fig, ax2 = plt.subplots()
    
ax2.bar(range(10), rand(10), picker = True)
  
for label in ax2.get_xticklabels(): 
    label.set_picker(True)
  
def onpick1(event):
      
    if isinstance(event.artist, Line2D):
        thisline = event.artist
        xdata = thisline.get_xdata()
        ydata = thisline.get_ydata()
        ind = event.ind
        print('onpick1 line:',
              np.column_stack([xdata[ind],
                               ydata[ind]]))
          
    elif isinstance(event.artist, Rectangle):
        patch = event.artist
        print('onpick1 patch:', patch.get_path())
          
    elif isinstance(event.artist, Text):
        text = event.artist
        print('onpick1 text:', text.get_text())
  
print("Value return : \n", *list(ax2.findobj()), sep ="\n")
  
fig.suptitle('matplotlib.axes.Axes.findobj() function Example',
             fontweight ="bold")
  
plt.show()


Output:

 

Value return : 

Rectangle(xy=(-0.4, 0), width=0.8, height=0.815228, angle=0)
Rectangle(xy=(0.6, 0), width=0.8, height=0.655121, angle=0)
Rectangle(xy=(1.6, 0), width=0.8, height=0.225002, angle=0)
Rectangle(xy=(2.6, 0), width=0.8, height=0.639457, angle=0)
Rectangle(xy=(3.6, 0), width=0.8, height=0.463923, angle=0)
Rectangle(xy=(4.6, 0), width=0.8, height=0.865994, angle=0)
Rectangle(xy=(5.6, 0), width=0.8, height=0.269864, angle=0)
Rectangle(xy=(6.6, 0), width=0.8, height=0.834427, angle=0)
Rectangle(xy=(7.6, 0), width=0.8, height=0.79638, angle=0)
Rectangle(xy=(8.6, 0), width=0.8, height=0.564809, angle=0)
Spine
Spine
Spine
Spine
Text(0.5, 0, '')
Text(1, 0, '')
Line2D()
Line2D()
Line2D((0, 0), (0, 1))
Text(0, 0, '')
Text(0, 1, '')

Line2D()
Line2D()
Line2D((0, 0), (0, 1))
Text(0, 0, '')
Text(0, 1, '')

Line2D()
Line2D()
Line2D((0, 0), (0, 1))
Text(0, 0, '')
Text(0, 1, '')

Line2D()
Line2D()
Line2D((0, 0), (0, 1))
Text(0, 0, '')
Text(0, 1, '')

Line2D()
Line2D()
Line2D((0, 0), (0, 1))
Text(0, 0, '')
Text(0, 1, '')

Line2D()
Line2D()
Line2D((0, 0), (0, 1))
Text(0, 0, '')
Text(0, 1, '')

Line2D()
Line2D()
Line2D((0, 0), (0, 1))
Text(0, 0, '')
Text(0, 1, '')

XAxis(80.0, 52.8)
Text(0, 0.5, '')
Text(0, 0.5, '')
Line2D()
Line2D()
Line2D((0, 0), (1, 0))
Text(0, 0, '')
Text(1, 0, '')

Line2D()
Line2D()
Line2D((0, 0), (1, 0))
Text(0, 0, '')
Text(1, 0, '')

Line2D()
Line2D()
Line2D((0, 0), (1, 0))
Text(0, 0, '')
Text(1, 0, '')

Line2D()
Line2D()
Line2D((0, 0), (1, 0))
Text(0, 0, '')
Text(1, 0, '')

Line2D()
Line2D()
Line2D((0, 0), (1, 0))
Text(0, 0, '')
Text(1, 0, '')

Line2D()
Line2D()
Line2D((0, 0), (1, 0))
Text(0, 0, '')
Text(1, 0, '')

YAxis(80.0, 52.8)
Text(0.5, 1.0, '')
Text(0.0, 1.0, '')
Text(1.0, 1.0, '')
Rectangle(xy=(0, 0), width=1, height=1, angle=0)
AxesSubplot(0.125, 0.11;0.775x0.77)

Example 2:




# Implementation of matplotlib function
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
  
  
fig, ax = plt.subplots()
x, y = 10 * np.random.rand(2, 1000)
ax.plot(x, y, 'go', alpha = 0.2)
  
circ = mpatches.Circle((0.5, 0.5), 0.25,
                       transform = ax.transAxes,
                       facecolor ='blue'
                       alpha = 0.75)
ax.add_patch(circ)
  
print("Value return : \n", *list(ax.findobj()),
      sep ="\n")
  
fig.suptitle('matplotlib.axes.Axes.findobj()\
function Example', fontweight ="bold")
  
plt.show()


Output:

 

Value return : 

Circle(xy=(0.5, 0.5), radius=0.25)
Line2D(_line0)
Spine
Spine
Spine
Spine
Text(0.5, 0, '')
Text(1, 0, '')
Line2D()
Line2D()
Line2D((0, 0), (0, 1))
Text(0, 0, '')
Text(0, 1, '')

Line2D()
Line2D()
Line2D((0, 0), (0, 1))
Text(0, 0, '')
Text(0, 1, '')

Line2D()
Line2D()
Line2D((0, 0), (0, 1))
Text(0, 0, '')
Text(0, 1, '')

Line2D()
Line2D()
Line2D((0, 0), (0, 1))
Text(0, 0, '')
Text(0, 1, '')

Line2D()
Line2D()
Line2D((0, 0), (0, 1))
Text(0, 0, '')
Text(0, 1, '')

Line2D()
Line2D()
Line2D((0, 0), (0, 1))
Text(0, 0, '')
Text(0, 1, '')

Line2D()
Line2D()
Line2D((0, 0), (0, 1))
Text(0, 0, '')
Text(0, 1, '')

Line2D()
Line2D()
Line2D((0, 0), (0, 1))
Text(0, 0, '')
Text(0, 1, '')

XAxis(80.0, 52.8)
Text(0, 0.5, '')
Text(0, 0.5, '')
Line2D()
Line2D()
Line2D((0, 0), (1, 0))
Text(0, 0, '')
Text(1, 0, '')

Line2D()
Line2D()
Line2D((0, 0), (1, 0))
Text(0, 0, '')
Text(1, 0, '')

Line2D()
Line2D()
Line2D((0, 0), (1, 0))
Text(0, 0, '')
Text(1, 0, '')

Line2D()
Line2D()
Line2D((0, 0), (1, 0))
Text(0, 0, '')
Text(1, 0, '')

Line2D()
Line2D()
Line2D((0, 0), (1, 0))
Text(0, 0, '')
Text(1, 0, '')

Line2D()
Line2D()
Line2D((0, 0), (1, 0))
Text(0, 0, '')
Text(1, 0, '')

Line2D()
Line2D()
Line2D((0, 0), (1, 0))
Text(0, 0, '')
Text(1, 0, '')

Line2D()
Line2D()
Line2D((0, 0), (1, 0))
Text(0, 0, '')
Text(1, 0, '')

YAxis(80.0, 52.8)
Text(0.5, 1.0, '')
Text(0.0, 1.0, '')
Text(1.0, 1.0, '')
Rectangle(xy=(0, 0), width=1, height=1, angle=0)
AxesSubplot(0.125, 0.11;0.775x0.77)
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32320 POSTS0 COMMENTS
Milvus
84 POSTS0 COMMENTS
Nango Kala
6683 POSTS0 COMMENTS
Nicole Veronica
11854 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11910 POSTS0 COMMENTS
Shaida Kate Naidoo
6795 POSTS0 COMMENTS
Ted Musemwa
7071 POSTS0 COMMENTS
Thapelo Manthata
6755 POSTS0 COMMENTS
Umr Jansen
6762 POSTS0 COMMENTS