`plt.show()` drops figures with `%run`
還沒有人認領這個 Issue。
評估
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 新手友好度
- 48/100
- Issue 類型
- 缺陷
- 描述清晰度
- 基本清楚
- 活躍度
- 活躍
- 技術堆疊
- jupyter, python
研究方向
Start in ipympl/backend_nbagg.py, at _Backend_ipympl.show() and the _closed flag around line 261, to see how figures get queued for display when interactive mode is on. Reproduce with the %run script from the issue, which turns interactive mode off, and compare which Gcf figures are active versus merely created. Done looks like every figure created during the %run is displayed, with the existing interactive-mode behavior unchanged.
由索引模型根據 Issue 內容生成。
描述
Describe the issue
Hi there 👾 This was originally opened on the Positron repo (which I am a maintainer of), but the behavior is coming from ipympl https://github.com/posit-dev/positron/issues/8020.
From a brief (🤖 assisted) exploration, it looks like with the ipympl backend, plt.show() only displays gcf.get_active(). Figures created while interactive mode is off are never queued for display, so every figure except the last one is silently dropped. You don't see this unless you're using the %run magic since that magic turns off the interactive mode. _Backend_ipympl.show() then only displays Gcf.get_active(), so figures created while interactive mode was off and not active are never displayed.
I'm happy to open up a PR if this is something you'd accept a contribution for! One idea for a small fix: if there's a flag to track if something is displayed (similar to _closed here), then you could make sure to open each figure, following the same steps as what is used to already display them.
To reproduce
If you run:
%matplotlib ipympl
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 2*np.pi, 100)
plt.figure(); plt.plot(x, np.sin(3*x))
plt.figure(); plt.plot(x, np.exp(3*x))
The output is 2 figures.
However, if you run the same code via the %run magic, only the last figure is shown.
%%writefile s.py
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 2*np.pi, 100)
plt.figure(); plt.plot(x, np.sin(3*x))
plt.figure(); plt.plot(x, np.exp(3*x))
%matplotlib ipympl
%run s.py
Versions
3.13.1 (main, Dec 3 2024, 17:59:52) [Clang 16.0.0 (clang-1600.0.26.4)]
ipympl version: 0.10.0
Selected Jupyter core packages...
IPython : 9.17.1
ipykernel : 7.4.0
ipywidgets : 8.1.9
jupyter_client : 8.10.0
jupyter_core : 5.9.1
jupyter_server : 2.21.1
jupyterlab : 4.6.6
nbclient : 0.11.0
nbconvert : 7.17.2
nbformat : 5.11.1
notebook : 7.6.5
qtconsole : not installed
traitlets : 5.16.1
- 主要語言
- Jupyter Notebook
- 星號
- 1.7k
- 分支
- 235
- PR 合併指標
- 30 天內沒有已合併 PR
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 沒有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
matplotlib/ipympl 的其他 Issue
-
難度 4/5 3-5 天 新手友好度 35/100
matplotlib/ipympl#623 · 1 則留言 ·
-
難度 4/5 3-5 天 新手友好度 35/100
matplotlib/ipympl#622 · 13 則留言 ·
-
Interactive graph in jupyterlab-rise presentation可能已有人在做 @f0k 於 4 天前認領。 未關閉
難度 4/5 3-5 天 新手友好度 42/100
matplotlib/ipympl#612 ·
-
DeprecationWarning: Passing unrecognized arguments to super(Toolbar).__init__().可能已有人在做 @pradeep14012004 於 59 天前認領。 未關閉
難度 3/5 1-2 天 新手友好度 45/100
matplotlib/ipympl#611 · 4 則留言 ·
-
難度 4/5 3-5 天 新手友好度 42/100
matplotlib/ipympl#609 · 7 則留言 ·
查看 matplotlib/ipympl 的全部 Issue
相似的 Issue
-
docs
難度 2/5 1-3 小時 新手友好度 78/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 88/100
WenjieDu/PyPOTS#1002 · 1 則留言 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 68/100
manta-plan/manta#526 ·
維護者通常 2 天內回覆
-
[Bug]: Saving a NonUniformImage with bbox_inches="tight" raises TypeError when extent is omitted未關閉
難度 2/5 1-3 小時 新手友好度 74/100
matplotlib/matplotlib#32707 ·
維護者通常 1 天內回覆
-
essreduce
難度 2/5 1-3 小時 新手友好度 69/100
維護者通常 1 天內回覆