Matplotlib.artist.Artist.set_visible() in Python
Matplotlib.artist.Artist.set_visible()
is a method in the Matplotlib library of Python that is used to set the visibility of an artist object. An artist object is any object that can be drawn using Matplotlib, such as a line, a scatter plot, or a text object.
The syntax for using set_visible()
is as follows:
artist.set_visible(visible)
Here, artist
is the artist object whose visibility is to be set, and visible
is a boolean value that determines whether the artist is visible or not. If visible
is True
, the artist is visible, and if it is False
, the artist is not visible.
Example:
import matplotlib.pyplot as plt
# Creating a scatter plot
x = [1, 2, 3, 4, 5]
y = [2, 4, 6, 8, 10]
plt.scatter(x, y)
# Setting the visibility of the scatter plot to False
plt.gca().get_children()[0].set_visible(False)
# Displaying the plot
plt.show()
In this example, we create a scatter plot using the scatter()
function of Matplotlib. We then use the get_children()
method to get a list of all the child objects of the current axis, and set the visibility of the first child object (which is the scatter plot) to False
using set_visible()
. This makes the scatter plot invisible when the plot is displayed.