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

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!