- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to clear the memory completely of all Matplotlib plots?
Using the following methods, we can clear the memory occupied by Matplotlib plots.
plt.figure() - Create a new figure or activate an existing figure.
plt.figure().close() - Close a figure window.
close() by itself closes the current figure
close(h), where h is a Figure instance, closes that figure
close(num) closes the figure number, num
close(name), where name is a string, closes figure with that label
close('all') closes all the figure windows
plt.figure().clear() - It is the same as clf.
plt.cla() - Clear the current axes.
plt.clf() - Clear the current figure.
Example
from matplotlib import pyplot as plt fig = plt.figure() plt.figure().clear() plt.close() plt.cla() plt.clf()
Output
When we execute the code, it will clear all the plots from the memory.
- Related Articles
- How to clear cache memory using JavaScript?
- How to reuse plots in Matplotlib?
- How to Annotate Matplotlib Scatter Plots?
- How to add annotations in Matplotlib Plots?
- How to save Matplotlib 3d rotating plots?
- How to animate a time-ordered sequence of Matplotlib plots?
- How to make semilogx and semilogy plots in Matplotlib?
- How to change the datetime tick label frequency for Matplotlib plots?
- How to merge two existing Matplotlib plots into one plot?
- How to plot half or quarter polar plots in Matplotlib?
- How to clear all cookies with JavaScript?
- How to clear all the input in HTML forms?
- Explain about the anatomy of Matplotlib plots in Python?
- How do I change the font size of the scale in Matplotlib plots?
- How to make several plots on a single page using Matplotlib?

Advertisements