iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more
Matplotlib plots usually fail to appear for one of four reasons: the code that creates them did not run, the wrong Python environment or notebook kernel is active, the current backend does not display a window, or the output is hidden. First identify where the code is running—standalone script, Jupyter notebook, or VS Code—then follow the matching checks below.
Start by confirming the code ran in the right place
Before changing Matplotlib settings, verify that execution reached the plotting code. In a script, make sure you ran the file that contains the plot. In a notebook or VS Code cell, run the cell again and inspect its output for an exception.
In a VS Code notebook, check that a kernel is selected and that it uses the Python environment where Matplotlib is installed. VS Code can use Python environments, Jupyter kernels, and existing Jupyter servers as kernel sources; see VS Code’s kernel management guide.
Check whether the active backend can display a plot
A Matplotlib backend determines how a figure is rendered: in a GUI window, as notebook output, or to a file. Check the active backend with:
#1 Best Overall
import matplotlib
print(matplotlib.get_backend())
Agg is a non-interactive backend. Matplotlib says it may be selected on Linux when no X or Wayland display is available, so a plot can be created without a pop-up window. See the Matplotlib backend guide for backend behavior and configuration.
Fix display behavior for your execution context
Standalone Python script
A script generally needs an explicit plt.show() call to display its figure:
Rank #2
import matplotlib.pyplot as plt
plt.plot([1, 4, 6])
plt.show()
If this still does not open a window, inspect the backend and check whether its GUI toolkit is installed and working. Matplotlib’s backend documentation includes a small standalone toolkit test for diagnosing installation issues.
Jupyter notebook
Jupyter’s inline, notebook, and widget backends call show() at the end of each cell by default. The inline backend displays a static image, not an interactive GUI window. Confirm the cell ran and that its output area is visible before changing backend settings.
For interactive notebook figures, Matplotlib documents the separately installed ipympl package. With notebook support and the package in place, select it using %matplotlib widget or %matplotlib ipympl. See Matplotlib’s interactive figures guide.
VS Code notebook or Python Interactive Window
- In a notebook, use the kernel picker to select the intended Python environment or Jupyter kernel.
- Run the cell, then inspect the notebook output. In the Python Interactive Window, run the code cell and inspect its result; VS Code supports Matplotlib plots there, including opening plots in the Plot Viewer. See VS Code’s Python Interactive Window documentation.
- If notebook rich output is missing, check whether the workspace is in Restricted Mode. VS Code documents Restricted Mode behavior in its Jupyter notebook guide.
Save a plot when you need a file, not a window
For a headless workflow or when the desired result is an image file, use savefig():
plt.savefig("plot.png")
If the file seems missing, check the script’s current working directory and the filename. If you also call a blocking plt.show(), save the figure first: the pyplot show reference warns that saving after a blocking show can save a new, empty figure.
Recommended Free Tools
Change the backend only when diagnosis points to it
Matplotlib can select a backend through rcParams, the MPLBACKEND environment variable, or matplotlib.use(); the last setting takes precedence. If you explicitly set a backend in code, call matplotlib.use(...) before creating any figures. The documentation cautions against setting MPLBACKEND globally because it can cause counterintuitive behavior.
Best Value
Prefer correcting the actual problem—such as selecting the right kernel or fixing a missing GUI toolkit—rather than forcing a backend without understanding the context. For more on configuration, consult the backend guide.
Quick Recap
Choose the display path that matches the job
| Need | Suitable path | Trade-off or check |
|---|---|---|
| Display a plot from a normal script | Interactive GUI backend and plt.show() |
Requires a working GUI toolkit and display connection. |
| See a quick result in Jupyter | Default inline output | Static image; it does not provide GUI interactivity. |
| Interact with a notebook figure | ipympl widget backend |
Requires the separate ipympl package and notebook support. |
| Generate an image in batch or headless mode | Non-interactive backend and savefig() |
Produces a file rather than an on-screen window. |
| Run notebook or code cells in VS Code | Selected kernel or environment and notebook or Interactive Window output | Confirm the intended kernel is selected and rich output is not hidden by Restricted Mode. |
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

