Matplotlib.pyplot.findobj() in Python (original) (raw)
Last Updated : 21 Apr, 2020
Matplotlib is an amazing visualization library in Python for 2D plots of arrays. Matplotlib is a multi-platform data visualization library built on NumPy arrays and designed to work with the broader SciPy stack.
matplotlib.pyplot.findobj()
This function is used to recursively find all instances of artists contained in the artist. Filters are created to match for the artist object which finds and returns a list of matched artists. An artist object refers to the object of matplotlib.artist
class that is responsible for rendering the paint on the canvas.
Syntax: matplotlib.pyplot.findobj(o=None, match=None, include_self=True)
Parameters:
- match: This parameter is used for the creating filter to match for the searched artist object. This can be one of three things;
- None: This returns all objects in artist.
- A function: A function with signature such as def match(artist: Artist) -> boolean. The result from this function has artists for which the function returns True.
- A class instance: The result of this contain artist of the same class or one of its subclasses(isinstance check), eg, Line2D
- **include_self:**This parameter accepts a boolean value and it includes itself to me checked for the list of matches.
Returns: It returns a list of Artist
Example 1:
import
matplotlib.pyplot as plt
import
numpy as np
h
=
plt.figure()
plt.plot(
range
(
1
,
11
),
`` range
(
1
,
11
),
`` gid
=
'dummy_data'
)
legend
=
plt.legend([
'the plotted line'
])
plt.title(
'figure'
)
axis
=
plt.gca()
axis.set_xlim(
0
,
5
)
for
p
in
set
(h.findobj(
lambda
x: x.get_gid()
=
=
'dummy_data'
)):
`` p.set_ydata(np.ones(
10
)
*
10.0
)
plt.show()
Output:
Example 2:
import
numpy as np
import
matplotlib.pyplot as plt
import
matplotlib.text as text
m
=
np.arange(
3
,
-
4
,
-
.
2
)
n
=
np.arange(
3
,
-
4
,
-
.
2
)
o
=
np.exp(m)
p
=
o[::
-
1
]
figure, axes
=
plt.subplots()
plt.plot(m, o,
'k--'
, m, p,
`` 'k:'
, m, o
+
p,
'k'
)
plt.legend((
' Modelset'
,
'Dataset'
,
`` 'Total string length'
),
`` loc
=
'upper center'
,
`` shadow
=
True
)
plt.ylim([
-
1
,
10
])
plt.grid(
True
)
plt.xlabel(
' Modelset --->'
)
plt.ylabel(
' String length --->'
)
plt.title(
'Min. Length of String'
)
def
find_match(x):
`` return
hasattr
(x,
'set_color'
)
and
not
hasattr
(x,
'set_facecolor'
)
for
obj
in
figure.findobj(find_match):
`` obj.set_color(
'black'
)
for
obj
in
figure.findobj(text.Text):
`` obj.set_fontstyle(
'italic'
)
plt.show()
Output:
Similar Reads
- Matplotlib.pyplot.grid() in Python Matplotlib is a library in Python and it is numerical - mathematical extension for NumPy library. Pyplot is a state-based interface to a Matplotlib module which provides a MATLAB-like interface. matplotlib.pyplot.grid() Function The grid() function in pyplot module of matplotlib library is used to c 2 min read
- Matplotlib.pyplot.gci() in Python Matplotlib is a library in Python and it is numerical – mathematical extension for NumPy library. Pyplot is a state-based interface to a Matplotlib module which provides a MATLAB-like interface. There are various plots which can be used in Pyplot are Line Plot, Contour, Histogram, Scatter, 3D Plot, 2 min read
- Matplotlib.pyplot.csd() in Python Matplotlib is a library in Python and it is numerical - mathematical extension for NumPy library. Pyplot is a state-based interface to a Matplotlib module which provides a MATLAB-like interface. matplotlib.pyplot.csd() Function The csd() function in pyplot module of matplotlib library is used to plo 3 min read
- matplotlib.pyplot.figure() in Python matplotlib.pyplot.figure() function is used to create a new figure for our plots. In Matplotlib a figure is like a blank space where all our plot elements such as axes, titles and labels are placed. In this article, we will see how to use figure() to create and customize figures using Python. Syntax 2 min read
- Matplotlib.pyplot.draw() in Python Matplotlib is a library in Python and it is numerical - mathematical extension for NumPy library. Pyplot is a state-based interface to a Matplotlib module which provides a MATLAB-like interface. matplotlib.pyplot.draw() Function The draw() function in pyplot module of matplotlib library is used to r 1 min read
- Matplotlib.pyplot.ginput() in Python Matplotlib is a library in Python and it is numerical – mathematical extension for NumPy library. Pyplot is a state-based interface to a Matplotlib module which provides a MATLAB-like interface. There are various plots which can be used in Pyplot are Line Plot, Contour, Histogram, Scatter, 3D Plot, 2 min read
- Matplotlib.pyplot.axis() in Python Matplotlib is a plotting library for creating static, animated, and interactive visualizations in Python. Pyplot is a Matplotlib module which provides a MATLAB-like interface. Matplotlib is designed to be as usable as MATLAB, with the ability to use Python and the advantage of being free and open-so 1 min read
- Matplotlib.pyplot.bone() in Python Matplotlib is a library in Python and it is numerical - mathematical extension for NumPy library. Pyplot is a state-based interface to a Matplotlib module which provides a MATLAB-like interface. There are various plots which can be used in Pyplot are Line Plot, Contour, Histogram, Scatter, 3D Plot, 2 min read
- matplotlib.pyplot.imshow() in Python matplotlib.pyplot.imshow() function in Python is used to display images in a plot. It is part of the matplotlib library and allows you to visualize images as 2D data. This function is widely used for displaying images, matrices, or heatmaps where each value in the array corresponds to a color. Examp 5 min read
- Matplotlib.pyplot.hist2d() in Python Matplotlib is a library in Python and it is numerical - mathematical extension for NumPy library. Pyplot is a state-based interface to a Matplotlib module which provides a MATLAB-like interface. matplotlib.pyplot.hist2d() Function The hist2d() function in pyplot module of matplotlib library is used 2 min read