What this thread does
Do first: call fig.savefig("plot.png", format="png") on the retained figure before pyplot.show() or any clearing operation.
Short answer
Diagnostic: blank image after a blocking show
As of November 2026, Matplotlib 3.11.2 documents that a blocking show() closes and unregisters figures on completion. A later stateful pyplot.savefig can therefore save a new empty figure. Keep the intended Figure and export it directly. show reference.
Choose / don't choose
- Explicit figure: choose
Figure.savefigfor reports with several figures or helper functions that change the active figure; don't infer ownership from the most recently active window. - Stateful pyplot: choose only when the active figure is deliberately controlled; don't call stateful save after closing its window.
- Show and save: save first for a simple lifecycle. A retained figure can still be exported after show; nonblocking show also differs from the blocking case.
Not for: app media pipeline selection; see image-and-video-processing-self-host-or-service-sharp-ffmpeg-mux.
Settings that matter
| Setting or flag | Value / default | Applies to | Source |
|---|---|---|---|
Figure.savefig(fname) | Save the target figure as an image or vector graphic to a file | Matplotlib current docs | Figure.savefig |
format | "png" explicitly; if not set, infer from the filename extension | Matplotlib current docs | savefig |
fname | Use "plot.png" with format="png"; explicit format does not repair or append the filename extension | Matplotlib current docs | savefig |
dpi | Default "figure"; use an explicit resolution only when the output contract needs it | Matplotlib current docs | savefig |
show(block=...) | Whether to wait for all figures to be closed before returning | Matplotlib current docs | show |
pyplot.close(fig) | Close the specified figure after exporting to release pyplot's retained reference | Matplotlib current docs | close |
Order of operations
1. Keep the fig returned by figure creation and plot into its axes. Check that the target contains the expected artists before exporting. 2. Call fig.savefig("plot.png", format="png") while those artists are intact. The extension and explicit format should agree. 3. Call pyplot.show() only if a window is needed. This displays all open figures; it does not select the export target. 4. Close that specific figure with pyplot.close(fig) after saving. In a batch report, omit show and close after each export. Saving cannot restore artists erased by clearing.
Known failures and fixes
| Error or symptom | Cause | Fix | Source |
|---|---|---|---|
| Blank file after closing the displayed window | Blocking show removed pyplot's registered figure; later stateful save selects an empty one | Export before show, or retain the figure and use its save method | show |
| Blank or wrong plot in a multi-figure report | Another figure may have been created before savefig; pyplot saves the current figure | Save through the original Figure reference | Benjamin Root, July 29, 2011 |
Root's reply distinguishes these two ownership failures; it is historical context, while the current API reference establishes the present behavior.
Missing
- A correct object and lifecycle do not diagnose every blank export. Empty data, cleared axes, clipping and backend-specific failures require inspecting the actual figure and output format.
- A blocking show is the documented empty-new-figure case; do not generalize it to all notebook or nonblocking display behavior.
Checked
2026-11-12; Matplotlib 3.11.2 release, Figure.savefig, pyplot.show and pyplot.close references, Roy Lowrance/Benjamin Root's July 2011 discussion read. No plotting commands executed.
Started from a post by @Matplotlib, packaged by the editor. Original post