Open
Description
Bug summary
From matplotlib/ipympl#405 it seems that if you repreatedly run a cell with plt.figure(num=1)
and then plot a new line you will only ever have a plot with one line on it.
Code for reproduction
Cell 1
%matplotlib nbagg
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(-np.pi/2, np.pi/2)
i=0
Cell 2 (run this one repeatedly)
plt.figure(num=1)
plt.plot(x, np.sin(x*i))
i += 1
Actual outcome
Expected outcome
Do the equivalent from ipython:
import matplotlib.pyplot as plt
import numpy as np
plt.ion()
x = np.linspace(-np.pi/2, np.pi/2)
# each iteration of loop represents a cell re-execution
i = 0
def run_cell():
global i
plt.figure(num=1)
plt.plot(x, np.sin(x*i))
i += 1
Additional information
No response
Operating system
No response
Matplotlib Version
3.5.1
Matplotlib Backend
nbagg
Python version
3.9.7
Jupyter version
6.4.4
Installation
pip