Closed Figure's state is silently changed in HTML export when plotting asynchronously
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 35/100
Direzione di ricerca
Inizia con il notebook allegato e l’esportazione HTML, utilizzando le versioni indicate di Python, ipympl, Jupyter e ipywidgets. Riproduci l’animazione asincrona con figure numerate e confrontala con la creazione di una nuova figura ogni volta. Il lavoro è completato quando l’HTML esportato conserva lo stato finale di ogni figura chiusa in precedenza invece di mostrare il primo valore di set_ydata.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Describe the issue
I know, this is a seemingly contrived example, but it's a real-world problem for me.
See attached Notebook and according HTML export
issue.zip
I'm running the notebook cell by cell, where I only start the next cell when the previous animation has been finished. The animation stops automatically. The code for animation is:
def runPlot(duration):
plt.close('all')
fig = plt.figure(1)
t = np.linspace(0, 1, 100)
data_line = plt.plot(t, np.sin(6.28*2*t))[0]
def _impl():
start = time.time()
it = 0
while time.time() - start < duration:
freq = time.time() - start
if it == 0:
data_line.set_ydata(t)
else:
data_line.set_ydata(np.sin(6.28*t*freq))
it = it + 1
fig.canvas.draw()
time.sleep(0.03)
T = threading.Thread(target=_impl)
T.start()
Within this code, a thread is started which shows a figure and continuously updates the ydata of the plotted line. The cell immediately returns, but the thread runs for the given amount of seconds. This leads to an animation in the notebook. Note that in the first iteration, a linear line is plotted instead of the sine wave. After running all cells, the notebook looks like this:
Upon pressing save and exporting to HTML, the exported HTML looks like this:
Apparently, for the HTML export, the state of the first plot widget has been replaced by the data that was first set by set_ydata. Adding more calls to runPlot only keeps the last figure in the correct shape for export, whereas the other figures contain the data initially set by set_ydata.
The problem does not happen when I create a new figure without a number all the time, i.e. replace this
plt.close('all')
fig = plt.figure(1)
with
fig = plt.figure()
However, as all figures are closed by close('all'), no data should be changed in previously open figures anymore.
Versions
$ python -c "import sys; print('\n',sys.version); import ipympl; print('ipympl version:', ipympl.__version__)" && jupyter --version && jupyter nbextension list && jupyter labextension list
3.13.1 (main, Dec 19 2024, 10:35:14) [GCC 11.1.0]
ipympl version: 0.9.5
Selected Jupyter core packages...
IPython : 8.30.0
ipykernel : 6.29.5
ipywidgets : 8.1.5
jupyter_client : 8.6.3
jupyter_core : 5.7.2
jupyter_server : 2.14.2
jupyterlab : 4.3.4
nbclient : 0.10.2
nbconvert : 7.16.4
nbformat : 5.10.4
notebook : 7.3.1
qtconsole : not installed
traitlets : 5.14.3
- Lingua principale
- Jupyter Notebook
- Stelle
- 1.7k
- Fork
- 234
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di matplotlib/ipympl
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
matplotlib/ipympl#623 · 1 commento ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
matplotlib/ipympl#622 · 13 commenti ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 42/100
matplotlib/ipympl#612 ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 45/100
matplotlib/ipympl#611 · 4 commenti ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 42/100
matplotlib/ipympl#609 · 6 commenti ·
Tutte le issue di matplotlib/ipympl
Issue simili
-
Browser Waiting for: Product Owner
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
getsentry/sentry-javascript#24577 · 1 commento ·
-
Cannot differ own consent and managed consents in My Consents view and detailed consent view. Aperta1.0.0-alpha2 Type/Improvement
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
wso2/dpdp-accelerator#272 ·
-
light
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
aemdemos/patients-stryker#253 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
clerk/javascript#9852 ·
-
bug good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
amponce/archive-movie-browser#165 ·