Saturday, September 27, 2025
HomeLanguagesMatplotlib.pyplot.clf() in Python

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




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

 

RELATED ARTICLES

Most Popular

Dominic
32321 POSTS0 COMMENTS
Milvus
84 POSTS0 COMMENTS
Nango Kala
6690 POSTS0 COMMENTS
Nicole Veronica
11857 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11912 POSTS0 COMMENTS
Shaida Kate Naidoo
6802 POSTS0 COMMENTS
Ted Musemwa
7073 POSTS0 COMMENTS
Thapelo Manthata
6763 POSTS0 COMMENTS
Umr Jansen
6768 POSTS0 COMMENTS