`groupclick="toggleitem"` Does Not Work Consistently Across Subplots in Plotly
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 18.8k
- 派生
- 2.8k
- 平均合并
- 16 小时 26 分钟
- 30 天内合并 PR
- 21
描述
Description
When using the groupclick="toggleitem" parameter in Plotly with subplots, the toggling behavior for legend items only applies to traces in the first subplot. Traces in other subplots are not affected as expected, even when the legendgroup attribute is set consistently for all relevant traces.
This issue breaks the intended behavior of groupclick="toggleitem" for figures with subplots, where users would expect the toggling of a legend item to apply uniformly across all traces in the same legendgroup, regardless of their subplot.
Expected Behavior
Clicking a legend item with groupclick="toggleitem" should toggle the visibility of all traces in the corresponding legendgroup, including traces in subplots other than the first.
Observed Behavior
When clicking a legend item:
-
The visibility of traces is toggled only in the first subplot.
-
Traces in other subplots within the same
legendgroupremain unaffected.
Minimal Reproducible Example
import plotly.graph_objects as go
from plotly.subplots import make_subplots
# Create a subplot figure
fig = make_subplots(rows=3, cols=1)
# Add traces to the first subplot
fig.add_trace(go.Scatter(x=[1, 2, 3], y=[1, 4, 9], name="Group A", legendgroup="group_a"), row=1, col=1)
fig.add_trace(go.Scatter(x=[1, 2, 3], y=[2, 4, 8], name="Group B", legendgroup="group_b"), row=1, col=1)
# Add traces to the second subplot
fig.add_trace(go.Scatter(x=[1, 2, 3], y=[1, 3, 6], name="Group A", legendgroup="group_a", showlegend=False), row=2, col=1)
fig.add_trace(go.Scatter(x=[1, 2, 3], y=[2, 5, 7], name="Group B", legendgroup="group_b", showlegend=False), row=2, col=1)
# Add traces to the third subplot
fig.add_trace(go.Scatter(x=[1, 2, 3], y=[1, 2, 3], name="Group A", legendgroup="group_a", showlegend=False), row=3, col=1)
fig.add_trace(go.Scatter(x=[1, 2, 3], y=[3, 5, 9], name="Group B", legendgroup="group_b", showlegend=False), row=3, col=1)
# Update layout with groupclick parameter
fig.update_layout(
legend=dict(groupclick="toggleitem")
)
fig.show()
Steps to Reproduce
-
Run the provided example code.
-
Click on a legend item for "Group A" or "Group B."
-
Observe that the traces in the first subplot toggle visibility as expected.
-
Notice that traces in other subplots do not toggle visibility.
### Environment
Plotly Version: 5.24.1
Python Version: 3.11.9
Operating System: Windows 11
Browser: Edge 131.0.2903.86
Additional Notes
The issue does not occur when the groupclick parameter is omitted. The default behavior works as expected, where clicking a legend item toggles all traces in the same legendgroup across all subplots.
However, groupclick="toggleitem" is necessary for more granular control of legend interactions, and it should work consistently across subplots.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先,使用 Plotly 5.24.1 运行提供的 Python 最小可复现示例,并验证全部三个子图中的图例行为。追踪 repository 或其 Plotly.js 集成中的图例交互入口,然后为共享图例组添加对 groupclick="toggleitem" 的覆盖。完成的标准是:点击图例项后,所有子图都能一致地应用预期的可见性变化。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- data-visualization
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 描述清楚
- 新手友好度
- 52/100