- 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 do I close all the open pyplot windows (Matplotlib)?
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 with number=num
close(name), where name is a string, closes the figure with that label
close('all') closes all the figure windows
Example
from matplotlib import pyplot as plt fig = plt.figure() ax = fig.add_subplot() plt.show() plt.close()
Output
Now, swap the statements "plt.show()" and "plt.close()" in the code. You wouldn't get to see any plot as the output because the plot would already have been closed.
- Related Articles
- How is the Pyplot histogram bins interpreted? (Matplotlib)
- How can I attach a pyplot function to a figure instance? (Matplotlib)
- How do I close a tkinter window?
- How can I get pyplot images to show on a console app? (Matplotlib)
- How do I get all the bars in a Matplotlib bar chart?
- How to zoom subplots together in Matplotlib/Pyplot?
- How do I handle the window close event in Tkinter?
- How can I set the background color on specific areas of a Pyplot figure using Matplotlib?
- How do I open Chrome in selenium WebDriver?
- How to safely open/close files in Python?
- How to fill the area under a step curve using pyplot? (Matplotlib)
- How do I create child windows with Python tkinter?
- How do I run a Python program under Windows?
- How do I open front camera programmatically on the Android platform?
- Saving all the open Matplotlib figures in one file at once

Advertisements