Matplotlib plot not showing in Jupyter Notebook or Google Colab

Jupyter Notebook · Visualization · Approx. 8 min read

You run your plotting code and either see nothing or only a text like [<matplotlib.lines.Line2D at 0x...>]. This guide shows the most common reasons Matplotlib plots don’t appear in Jupyter / Colab – and how to fix them quickly.

1. Use %matplotlib inline (classic Jupyter)

import matplotlib.pyplot as plt
%matplotlib inline

Put this near the top of your notebook, then create your plots in later cells.

2. Call plt.show() at the end of the cell

plt.plot([1, 2, 3], [1, 4, 9])
plt.xlabel("x")
plt.ylabel("y")
plt.title("Example plot")
plt.show()

In some setups, especially when using multiple backends, explicitly calling plt.show() ensures the plot is rendered.

3. Keep all plotting code in one cell

Splitting figure creation across multiple cells (create figure in one, show in another) can lead to no output (or only object reprs). Group related plotting commands together:

import matplotlib.pyplot as plt

%matplotlib inline

fig, ax = plt.subplots()
ax.plot([1, 2, 3], [1, 4, 9])
ax.set_xlabel("x")
ax.set_ylabel("y")
ax.set_title("Example")
plt.show()

4. In Colab, backend is already configured

In Google Colab you usually don’t need %matplotlib inline. Just make sure you import Matplotlib and call plt.show(). If the plot still doesn’t show, restart runtime and rerun all cells.

5. Save a working plotting setup with NoteCapsule

Once plotting works for a project, capture a NoteCapsule snapshot so future collaborators (or future you) can run the same notebook and see the figures without backend headaches.

from notebookcapsule import create_capsule

create_capsule(
    name="plots-working",
    notebook_path="notebooks/visualization.ipynb",
    data_dirs=["./data"],
    base_dir=".",  # project root
)

Never debug plotting issues twice for the same project

NoteCapsule helps you preserve a complete, working notebook environment – including plotting settings – so your figures keep showing up on any machine.

Join NoteCapsule early access