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

Ticklabels can not be middle aligned when using a weekly period

未關閉
#5,293 0 則留言 1 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

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

研究方向

首先執行報告中的最小 Python 範例,並比較日、月和週期的情況。追蹤週期的週期模式刻度標籤對齊行為,並找出相關的 Plotly 實作和回歸測試位置。完成的標準是:週標籤能夠自適應地置中,且不進行基於像素的偏移,同時其他週期情況保持正確。

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

描述

bug P3

Plotly version: 6.2.0

Minimal Example
import plotly.graph_objects as go
import pandas as pd

data = [
    {"date": "2025-07-20", "total_sales": 23.34},
    {"date": "2025-07-27", "total_sales": 45.21},
    {"date": "2025-08-03", "total_sales": 12.98},
    {"date": "2025-08-10", "total_sales": 41.32},
]

df = pd.DataFrame.from_records(data)

def make_figure(df, period, step, title):
    fig = go.Figure()
    fig.add_trace(go.Bar(
        x=df['date'],
        y=df['total_sales'],
        xperiod=period,
        xperiod0=df['date'].min(),
        xperiodalignment="middle"
    ))
    fig.update_layout(
        xaxis={
            'ticklabelmode': 'period',
            'tickmode': 'linear',
            'dtick': period,
            'tick0': df['date'].min(),
            'ticklabelstep': step
        },
        title={
            'text': title
        })
    fig.show(renderer="browser")

MS_PER_DAY = 24 * 60 * 60 * 1000
make_figure(df, MS_PER_DAY, 7, "Period = 1 Day")
make_figure(df, MS_PER_DAY * 7, 1, "Period = 7 Days")

When plotting aggregated timeseries data in period mode, the ticklabels are aligned to the middle of the bar when the period is 1 day or even 1 month, but if I try to use a period of 1 week the ticklabels are aligned to the left side of the column.

Image Image

I cannot use ticklabelshift to move the labels towards the center since ticklabelshift requires the measurement in pixels and what I'm building is repsonsive, so the width of the chart in pixels is variable

主要語言
Python
星號
18.8k
分支
2.8k
平均合併
14 小時 12 分鐘
30 天內合併 PR
19

環境準備

從這裡開始

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

plotly/plotly.py 的其他 Issue

查看 plotly/plotly.py 的全部 Issue

相似的 Issue

更多 Python Issue

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

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