Default bar width on date axes should be smarter
未关闭
还没有人认领这个 Issue。
feature
P3
- 主要语言
- Python
- 星标
- 18.8k
- 派生
- 2.8k
- 平均合并
- 16 小时 26 分钟
- 30 天内合并 PR
- 21
描述
This is likely a similar issue to https://github.com/plotly/plotly.js/issues/6199
Plotly version: 6.2.0
Minimal Example
import plotly.graph_objects as go
import pandas as pd
import datetime
data = [
{"date": datetime.date(2025,7,20), "net_sales": 23.34, "gross_sales": 32.98},
{"date": datetime.date(2025,7,21), "net_sales": 45.21, "gross_sales": 68.12},
{"date": datetime.date(2025,7,22), "net_sales": 12.98, "gross_sales": 34.54},
{"date": datetime.date(2025,7,23), "net_sales": 41.32, "gross_sales": 45.32},
]
df = pd.DataFrame.from_records(data)
def make_figure(df, width=None):
fig = go.Figure()
fig.add_trace(go.Bar(
x=df['date'],
y=df['net_sales'],
xperiod=24*60*60*1000,
xperiod0=df['date'].min(),
xperiodalignment="middle"
))
fig.add_trace(go.Bar(
x=df['date'],
y=df['gross_sales'],
xperiod=24*60*60*1000,
xperiod0=df['date'].min(),
xperiodalignment="middle"
))
fig.update_layout(
xaxis={
'ticklabelmode': 'period',
'tickmode': 'auto',
'dtick': 24*60*60*1000,
'range': (df['date'].min(), df['date'].max() + datetime.timedelta(days=1))
})
fig.show(renderer="browser")
make_figure(df)
make_figure(df[0:1])
When plotting a bar chart of aggregated timeseries data, strange behaviour happens when there's only 1 data point or group. When there are multiple bars each bar is displayed as one would expect (first screenshot below), but when there's only a single data point the bar is invisible, and specifically the bar width is set to 1ms or 0.5px (second screenshot).
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 issue 中的最小 Python 示例开始,并将行为与 plotly.js issue #6199 进行比较。当单个日期点能够以合理的默认宽度渲染出可见的条形,而多点条形仍保持当前行为时,即视为完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- data-visualization
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 38/100