Bug: leftover xaxis entries when toggling between buttons
未关闭
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 18.8k
- 派生
- 2.8k
- 平均合并
- 16 小时 26 分钟
- 30 天内合并 PR
- 21
描述
Minimum Working Example (MWE):
import plotly.graph_objects as go
from plotly.subplots import make_subplots
# Data
option1_x = ['A', 'B', 'C']
option1_y1 = [1, 3, 2]
option1_y2 = [2, 4, 3]
option2_x = ['B', 'D', 'E']
option2_y1 = [2, 1, 4]
option2_y2 = [3, 2, 5]
# Create subplots
fig = make_subplots(rows=2, cols=1, shared_xaxes=True, subplot_titles=("y1", "y2"))
# Add traces for option1
fig.add_trace(go.Bar(x=option1_x, y=option1_y1, name="option1_y1"), row=1, col=1)
fig.add_trace(go.Bar(x=option1_x, y=option1_y2, name="option1_y2"), row=2, col=1)
# Add traces for option2
fig.add_trace(go.Bar(x=option2_x, y=option2_y1, name="option2_y1"), row=1, col=1)
fig.add_trace(go.Bar(x=option2_x, y=option2_y2, name="option2_y2"), row=2, col=1)
# Initially set option1 visible and option2 invisible
for trace in fig.data:
trace.visible = False
fig.data[0].visible = True # y1 option1
fig.data[1].visible = True # y2 option1
# Add buttons
fig.update_layout(
updatemenus=[
{
"type": "buttons",
"buttons": [
{
"label": "option1",
"method": "update",
"args": [
{"visible": [True, True, False, False]}, # Show only option1 traces
]
},
{
"label": "option2",
"method": "update",
"args": [
{"visible": [False, False, True, True]}, # Show only option2 traces
]
}
],
"showactive": True,
}
],
)
fig.show()
Toggling to option2, we can see the C xaxis entry (from option1) still showing (even with no data for it):
This seems to only be an issue with subplots, and when the traces of different options have some xaxis labels in common (in this case B).
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先运行提供的 Python MWE,并在 subplot 图中切换 option1 和 option2 按钮。检查隐藏 traces 时共享的 x 轴条目是如何保留的,以及这些选项共享标签 B 时的情况。完成标准是:切换到 option2 后,不再显示 option1 遗留的 C x 轴条目。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- data-visualization
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 活跃
- 描述清晰度
- 基本清楚
- 新手友好度
- 55/100