Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Ticklabels can not be middle aligned when using a weekly period #5293

Open
Labels
P3backlog bugsomething broken
@logankopas

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3backlog bugsomething broken

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /