plotly / plotly/plotly.py

Ticklabels can not be middle aligned when using a weekly period

Open
#5,293 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug P3
Dominant language
Python
Stars
18.8k
Forks
2.8k
Avg merge
16h 26m
Merged PRs (30d)
21

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the minimal Python example from the report and compare the daily, monthly, and weekly period cases. Trace the period-mode tick-label alignment behavior for weekly periods and identify the relevant Plotly implementation and regression-test location. Done means weekly labels are centered responsively without pixel-based shifting, while the other period cases remain correct.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data-visualization
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.