Skip to content
Related Articles

Related Articles

Improve Article

Matplotlib.pyplot.fignum_exists() in Python

  • Last Updated : 10 May, 2020
Geek Week

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, etc.

matplotlib.pyplot.fignum_exists() method

The fignum_exists() method in pyplot module of matplotlib library is used to get whether the figure with the given id exists.

Syntax: matplotlib.pyplot.fignum_exists(num)

num: This parameter is the figure number.

Returns: This method returns whether the figure with the given id exists or not.

Below examples illustrate the matplotlib.pyplot.fignum_exists() function in matplotlib.pyplot:

Example 1:

#Implementation of matplotlib function
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(20) / 50
y = (x + 0.1)*3
val1 = [True, False] * 10
val2 = [False, True] * 10
plt.errorbar(x, y, 
             label='Line 1')
y = (x + 0.3)*3
y = (x + 0.6)*4
plt.errorbar(x + 1.2,
             label='Line 3')
plt.text(0.5, 3.7,
         "Figure 1 Exists ? " +
         str(plt.fignum_exists(1)) ,
Example' ,fontweight="bold" 


Example 2:

# Implementation of matplotlib function
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0, 10, 500)
y = np.sin(x**2)+np.cos(x)
plt.plot(x, y, label ='Line 1')
plt.plot(x, y - 0.6, label ='Line 2')
plt.text(2.5, 1.9,
         "Figure 2 Exists ? " +
         fontweight ="bold")
 Example', fontweight ="bold" 


 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course

My Personal Notes arrow_drop_up
Recommended Articles
Page :