VOOZH about

URL: https://www.geeksforgeeks.org/python/difference-between-cla-clf-and-close-methods-in-matplotlib/

⇱ Difference Between cla(), clf() and close() Methods in Matplotlib - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Difference Between cla(), clf() and close() Methods in Matplotlib

Last Updated : 23 Jul, 2025

Matplotlib is a library in Python. It is a mathematical extension of the Numpy Library. It is a comprehensive library for creating static, animated, and interactive visualizations in Python. Pyplot is a state-based interface to a Matplotlib module. The Pyplot can create many types of plots such as line graphs, bar graphs, histograms, etc. The cla(), clf() and close() are different methods and functions of Matplotlib.

What is cla() in Matplotlib

This cla()method in the Pyplot module of the Matplotlib library is used to clear the current axes.

Example:

Output:

👁 Image
The subplot ax1 content is cleared.

What is clf() in Matplotlib

The clf() method in the Pyplot module of the Matplotlib library is used to clear the entire current figure. It even clears the subplot. It leaves the window space open so that it can be reused by other plots.

Example:

Output:

👁 Image
The clf() function cleared the entire figure and only space is left.

What is close() Matplotlib 

The close() method in the Pyplot module of the Matplotlib library is used to close the window of the plot. By default, it closes the current window. Since the window is closed there will no output in this method.

Example:

Difference Between cla() vs. clf() vs. close()

cla()clf()close()
Used to clear the current axesUsed to clear the entire current figureUsed to close the window of the plot
It only clears the currently active plotLeaves the window space open so that it can be reused by other plotsTerminates the plot completely
Doesn't affect any other subplotIt even clears the subplot.Closes the plots entirely
Comment
Article Tags: