Bar charts don't group when there's only 1 group
@camdecoster đang làm issue này rồi.
Từ ngày 1/8/2025.
Đánh giá
Issue này chưa được đánh giá.
Mô tả
I found this issue while trying to work around https://github.com/plotly/plotly.py/issues/5294
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['gross_sales'],
xperiod=24*60*60*1000,
xperiod0=df['date'].min(),
xperiodalignment="middle",
width=24*60*60*1000 * 0.4,
opacity=0.6,
offsetgroup='gross' # same behaviour exhibited whether or not this is specified
))
fig.add_trace(go.Bar(
x=df['date'],
y=df['net_sales'],
xperiod=24*60*60*1000,
xperiod0=df['date'].min(),
xperiodalignment="middle",
width=24*60*60*1000 * 0.4,
opacity=0.6,
offsetgroup='net' # same behaviour exhibited whether or not this is specified
))
fig.update_layout(
barmode='group',
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 grouped bar chart of aggregated timeseries data, strange behaviour happens when there's only 1 group in the data. When there are multiple groups of data each bar is displayed as one would expect (first screenshot below), but when there's only a single data point the bars overlap (second screenshot). These bars overlap regardless of whether the offsetgroup or alignmentgroup is specified, and the offset must be manually set in order to get consistent behaviour regardless of the data provided.
- 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
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.
Issue khác của plotly/plotly.py
-
P3 size: 1 task
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
-
bug P1
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 68/100
-
feature P3
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
-
feature P3
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
Tất cả issue của plotly/plotly.py
Issue tương tự
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
zostera/django-bootstrap4#894 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
use-agent-os/agent-os#3276 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
zephyrproject-rtos/zephyr#119726 ·
-
area/auth bug comp/agent P3 platform/discord type/security
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
NousResearch/hermes-agent#117848 ·