Plot disappears after executing cell second time

Open
#60 13 comments 9 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
jupyter-notebook, matplotlib, python

Research direction

Start by reproducing the two notebook-cell examples in JupyterLab and Jupyter Notebook with the reported widget and inline backends. Compare repeated execution of the plotting cell and confirm that the widget-backed plot remains visible and re-renders as expected without rerunning the backend-selection cell.

Written by the indexing model from the issue text.

Description

If I have a plot in a notebook cell, and execute it twice, the plot output disappears. This is not what is expected. For example, using this code in one jupyter notebook cell:

%matplotlib widget
import matplotlib.pyplot as plt

and this in another cell:

x = [0, 1, 2, 3]
y = [0, 1, 2, 3]

plt.plot(x, y)

The first time I run this, everything plots fine. But when I execute the second cell twice (or any following calls), the plot disappears. The expected behaviour is that it re-plots (using a different colour). If I then re-run the first cell (with %matplotlib widget), and then the second cell again, it works (but this basically just resets the plot).

If I include a plot command in the first cell, then I can re-run the second cell as many times as I want and it works as expected.

This does not happen if I use %matplotlib inline. I've tested in both jupyter lab and jupyter notebook. My versions are the following:

matplotlib                2.2.2                    py36_1    conda-forge
ipympl                    0.2.1                    py36_0    conda-forge
@jupyter-widgets/jupyterlab-manager
        @jupyter-widgets/jupyterlab-manager v0.35.0  enabled  OK
Dominant language
Jupyter Notebook
Stars
1.7k
Forks
234
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from matplotlib/ipympl

All issues in matplotlib/ipympl

Similar issues

More Data Visualization issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.