Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

Bug: leftover xaxis entries when toggling between buttons

未關閉
#4,849 2 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
3/5
預估耗時
1-2 天
新手友好度
55/100
Issue 類型
缺陷
描述清晰度
基本清楚
活躍度
活躍
技術堆疊
python

研究方向

首先執行提供的 Python MWE,並在 subplot 圖中切換 option1 和 option2 按鈕。檢查隱藏 traces 時共用的 x 軸項目如何被保留,以及這些選項共用標籤 B 時的情況。完成標準是:切換到 option2 後,不再顯示 option1 遺留的 C x 軸項目。

由索引模型根據 Issue 內容生成。

描述

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()

Image

Toggling to option2, we can see the C xaxis entry (from option1) still showing (even with no data for it):

Image

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).

主要語言
Python
星號
18.8k
分支
2.8k
平均合併
13 小時 28 分鐘
30 天內合併 PR
20

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

plotly/plotly.py 的其他 Issue

查看 plotly/plotly.py 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。