[BUG]: FigureWidget: layout.shapes not updated after drawing a path in JupyterLab
@emilykl 已經在處理了。
開始於 2026年8月3日。
評估
這個 Issue 還沒有評估資料。
描述
Description
When attempting to enable draw closed paths on a plotly.graph_objects.FigureWidget, I noticed that there was an issue when attempting to delete the existing drawn paths. It seems that while fig.layout.to_plotly_json().get("shapes") is able to detect the path drawn, this information is not relayed to fig.layout.shapes. This can be fixed by manually editing fig.layout.to_plotly_json().get("shapes"), plugging it into fig.layout.shapes, and then deleting. The manual edits are to remove the <object object at 0x000001BFE6411440> that is assigned to both "name" and "legendwidth".
Steps to reproduce
import plotly.graph_objects as go
import ipywidgets as widgets
from IPython.display import display
fig = go.FigureWidget(
go.Heatmap(
z=[[1, 2], [3, 4]],
showscale=False,
)
)
fig.update_layout(
dragmode="drawclosedpath",
newshape=dict(
line=dict(color="red", width=2)
)
)
fail_clear_button = widgets.Button(description="Clear ROI (Fails)")
working_clear_button = widgets.Button(description="Clear ROI (Works)")
out = widgets.Output()
def clear_roi(_):
with out:
print("layout.shapes:", fig.layout.shapes)
print("JSON shapes:", fig.layout.to_plotly_json().get("shapes"))
with fig.batch_update():
fig.layout.shapes = []
print("After update_layout")
print("layout.shapes:", fig.layout.shapes)
print("JSON shapes:", fig.layout.to_plotly_json().get("shapes"))
def clear_roi_alt(_):
with out:
print("layout.shapes:", fig.layout.shapes)
print("JSON shapes:", fig.layout.to_plotly_json().get("shapes"))
json_shapes = fig.layout.to_plotly_json().get("shapes", [])
for s in json_shapes:
s['legendwidth'] = 0
s['name'] = ''
fig.layout.shapes = json_shapes
print("After pulling from JSON")
print("layout.shapes:", fig.layout.shapes)
print("JSON shapes:", fig.layout.to_plotly_json().get("shapes"))
fig.layout.shapes = []
print("After clearing")
print("layout.shapes:", fig.layout.shapes)
print("JSON shapes:", fig.layout.to_plotly_json().get("shapes"))
fail_clear_button.on_click(clear_roi)
working_clear_button.on_click(clear_roi_alt)
display(widgets.VBox([fail_clear_button, working_clear_button, fig, out]))
Notes
Python: 3.12.13
Plotly: 6.9.0
JupyterLab: 4.5.6
ipywidgets: 8.1.8
OS: Windows-11-10.0.26100-SP0
- 主要語言
- Python
- 星號
- 18.8k
- 分支
- 2.8k
- 平均合併
- 13 小時 28 分鐘
- 30 天內合併 PR
- 20
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
plotly/plotly.py 的其他 Issue
-
P3 size: 1 task
難度 2/5 1-3 小時 新手友好度 65/100
-
P3 size: 1 task
難度 2/5 1-3 小時 新手友好度 72/100
-
bug P1
難度 1/5 1 小時以內 新手友好度 68/100
-
feature P3
難度 2/5 1-3 小時 新手友好度 62/100
-
feature P3
難度 2/5 1-3 小時 新手友好度 72/100
相似的 Issue
-
bug confirmed issue
難度 2/5 1-3 小時 新手友好度 75/100
open-webui/open-webui#30750 · 1 則留言 ·
-
難度 2/5 1-3 小時 新手友好度 75/100
-
enhancement
難度 2/5 1-3 小時 新手友好度 75/100
OpenwaterHealth/openmotion-bloodflow-app#604 · 1 則留言 ·
-
難度 2/5 1-3 小時 新手友好度 70/100
-
good first issue
難度 1/5 1 小時以內 新手友好度 90/100