Open In App

Matplotlib.pyplot.clf() in Python

Last Updated : 25 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

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

# Implementation of matplotlib function
importmatplotlib.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

# Implementation of matplotlib function
importnumpy as np
importmatplotlib.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 
 


 



Next Article
Practice Tags :

Similar Reads

close