Ticklabels can not be middle aligned when using a weekly period
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 18.8k
- Fork
- 2.8k
- Merge trung bình
- 16 giờ 26 phút
- Pull request đã merge (30 ngày)
- 21
Mô tả
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
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu bằng cách chạy ví dụ Python tối thiểu trong báo cáo và so sánh các trường hợp khoảng thời gian theo ngày, tháng và tuần. Theo dõi hành vi căn chỉnh nhãn tick ở chế độ period đối với các khoảng thời gian theo tuần và xác định phần triển khai Plotly liên quan cũng như vị trí của bài kiểm thử hồi quy. Được xem là hoàn tất khi các nhãn theo tuần được căn giữa một cách đáp ứng mà không dịch chuyển dựa trên pixel, trong khi các trường hợp khoảng thời gian khác vẫn chính xác.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- python
- Lĩnh vực
- data-visualization
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 48/100