-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Open
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.


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
Labels
No labels