Matplotlib.pyplot.clf() in Python
Last Updated :
21 Sep, 2021
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.clf() Function
The clf() function in pyplot module of matplotlib library is used to clear the current figure.
Syntax:
matplotlib.pyplot.clf()
Below examples illustrate the matplotlib.pyplot.clf() function in matplotlib.pyplot:
Example 1:
Python3
import matplotlib.pyplot as plt
plt.plot([ 1 , 2 , 3 , 4 ], [ 16 , 4 , 1 , 8 ])
plt.clf()
plt.title( 'matplotlib.pyplot.clf Example' )
plt.show()
|
Output:
Example 2:
Python3
import numpy as np
import matplotlib.pyplot as plt
t = np.linspace( 0.0 , 2.0 , 201 )
s = np.sin( 2 * np.pi * t)
plt.ylabel( 'y-axis' )
plt.xlabel( 'x-axis' )
plt.plot(t, s)
plt.grid( True )
plt.clf()
plt.title( 'matplotlib.pyplot.clf Example' )
plt.show()
|
Output:
Before using clf() function
After using clf() function
Share your thoughts in the comments
Please Login to comment...