Wednesday, November 27, 2024
Google search engine
HomeLanguagesMatplotlib.pyplot.fignum_exists() in Python

Matplotlib.pyplot.fignum_exists() 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, 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)

Parameters:
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, 
             xerr=0.1,
             xlolims=True,
             label='Line 1')
  
y = (x + 0.3)*3
     
y = (x + 0.6)*4
  
plt.errorbar(x + 1.2,
             y,
             xerr=0.1,
             xuplims=True
             label='Line 3')
     
plt.legend()
  
plt.text(0.5, 3.7,
         "Figure 1 Exists ? " +
         str(plt.fignum_exists(1)) ,
         fontweight="bold")
  
plt.title('matplotlib.pyplot.fignum_exists()function\
Example' ,fontweight="bold"
  
plt.show() 


Output:

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 ? " +
         str(plt.fignum_exists(2)), 
         fontweight ="bold")
  
plt.title('matplotlib.pyplot.fignum_exists()function\
 Example', fontweight ="bold"
  
plt.show() 


Output:

Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments