October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk2 min

Matplotlib Inline in Python: Display Static Plots in Jupyter

Use %matplotlib inline to render static Matplotlib figures beneath notebook cells. For pan and zoom, install ipympl and select its widget backend in a supported frontend.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use %matplotlib inline in an IPython-backed Jupyter notebook to display Matplotlib plots as static output beneath the cell that creates them. It is a notebook magic, not standard Python syntax for a regular .py script. If you need to pan, zoom, or otherwise interact with a plot, use the separate ipympl widget backend in a supported notebook instead.

What %matplotlib inline does

The %matplotlib inline magic selects Matplotlib’s inline notebook backend. When a plotting cell runs, its figure is rendered as notebook output. The output is static: changing data or code in a later cell does not change an already rendered plot. Rerun the plotting cell to create a new output. Matplotlib also notes that the default inline backend adjusts the displayed figure to a tight box around the artists in it. Matplotlib’s image tutorial describes inline display and its limits; its figure introduction covers the default backend’s static behavior.

Display a plot inline

Enter the magic in a notebook cell, then create and plot data with Matplotlib’s usual pyplot interface:

%matplotlib inline
import matplotlib.pyplot as plt

fig, ax = plt.subplots()
ax.plot([1, 2, 3], [1, 4, 9])

Run the cell to display the figure below it. The fig, ax = plt.subplots() and ax.plot(...) pattern is also used in Matplotlib’s getting-started guide. The magic is specific to IPython-style environments; do not paste it into a regular Python script, where it is not valid Python syntax.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose inline or interactive display

What you need Use Important detail
A chart embedded beneath a notebook cell %matplotlib inline Static output; rerun the plotting cell to update it.
Notebook pan, zoom, or other figure interaction Install ipympl and activate %matplotlib widget or %matplotlib ipympl Requires a supported frontend and the separate package.
A plot in a script or GUI application Select a suitable Matplotlib GUI backend and use the display workflow for that environment Inline magic is a notebook/IPython workflow; backend behavior depends on the environment.

Matplotlib’s ipympl documentation shows the interactive widget backend and supported notebook environments. For current notebook-version guidance, Matplotlib associates %matplotlib widget with ipympl in JupyterLab or Notebook 7 and newer; for Notebook versions below 7 or nbclassic, its guidance identifies %matplotlib notebook as the older interactive option. Check the frontend and version you actually use before choosing that legacy magic. Matplotlib’s backend guidance distinguishes these options.

Install and activate the interactive alternative

If you need an interactive notebook plot, install ipympl in the environment used by the notebook. The project documents both pip and conda-forge installation:

pip install ipympl
conda install -c conda-forge ipympl

Then select the widget backend in a notebook cell:

%matplotlib widget

You can also use %matplotlib ipympl. If the magic is unrecognized or the widget does not render, confirm that the package is installed in the notebook’s active environment and that the frontend supports it; installation in a different Python environment will not enable it for the current kernel. See the ipympl setup instructions.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

What a Matplotlib backend means

A backend connects Matplotlib’s figures to a mechanism that renders or displays them. In an ordinary notebook workflow, you select the display behavior with an IPython magic such as %matplotlib inline; you do not need to write a backend yourself. Backend implementation is relevant when building a custom integration, not for displaying a routine notebook chart. Matplotlib’s backend documentation explains the interface.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.