Bug Report: Template updatemenus and annotations not transferred to figures
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 18.8k
- 派生
- 2.8k
- 平均合并
- 16 小时 26 分钟
- 30 天内合并 PR
- 21
描述
Bug Report: Template updatemenus and annotations not transferred to figures
Description
When defining updatemenus and annotations in a Plotly template, they are not properly transferred to figures that use the template. While other template properties (like colors, fonts, etc.) are transferred correctly, updatemenus and annotations are created as empty lists.
Expected Behavior
All layout properties defined in a template, including updatemenus and annotations, should be transferred to figures that use the template.
Actual Behavior
fig.layout.updatemenusandfig.layout.annotationsare created (notNone)- However, they are empty lists, losing all content defined in the template
- Other template properties (like
paper_bgcolor) are transferred correctly
Minimal Reproducible Example
import plotly.graph_objects as go
import plotly.io as pio
import numpy as np
# Create template with updatemenus and annotations
my_template = go.layout.Template(
layout=dict(
updatemenus=[
dict(
buttons=[
dict(
label="View 1",
method="relayout",
args=[{"scene.camera.eye": dict(x=1, y=1, z=1)}],
),
],
direction="down",
showactive=True,
x=0.1,
y=1.1,
),
],
annotations=[
dict(
text="Test annotation",
x=0.5,
y=1.1,
xref="paper",
yref="paper",
showarrow=False,
),
],
paper_bgcolor="rgb(240,240,240)", # This works correctly
)
)
# Register template
pio.templates["my_template"] = my_template
# Create figure with template
fig = go.Figure(
data=[go.Scatter3d(
x=np.random.normal(0, 1, 100),
y=np.random.normal(0, 1, 100),
z=np.random.normal(0, 1, 100),
mode="markers",
)]
)
fig.update_layout(template="my_template")
# Check results
print("Template updatemenus length:", len(my_template.layout.updatemenus)) # 1
print("Figure updatemenus length:", len(fig.layout.updatemenus)) # 0
print("Template annotations length:", len(my_template.layout.annotations)) # 1
print("Figure annotations length:", len(fig.layout.annotations)) # 0
Current Workaround
The only workaround is to manually apply the updatemenus and annotations after applying the template:
fig.update_layout(
updatemenus=my_template.layout.updatemenus,
annotations=my_template.layout.annotations,
)
Environment
- Python: 3.11.7
- Plotly: 5.24.1
- OS: Linux
Additional Context
This issue affects any template that tries to define interactive UI elements like buttons or annotations. The workaround requires additional code and makes templates less useful for defining reusable UI components.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 issue 中的最小可复现示例开始,跟踪 fig.update_layout(template="my_template") 如何应用 layout 属性。比较 template 与 figure 的 updatemenus 和 annotations,然后添加回归测试,证明它们的内容会被传递,同时 paper_bgcolor 保持正确。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- data-visualization
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 45/100