Saturday, September 6, 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
32270 POSTS0 COMMENTS
Milvus
82 POSTS0 COMMENTS
Nango Kala
6639 POSTS0 COMMENTS
Nicole Veronica
11803 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11869 POSTS0 COMMENTS
Shaida Kate Naidoo
6752 POSTS0 COMMENTS
Ted Musemwa
7029 POSTS0 COMMENTS
Thapelo Manthata
6705 POSTS0 COMMENTS
Umr Jansen
6721 POSTS0 COMMENTS