Default bar width on date axes should be smarter
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 18.8k
- Fork
- 2.8k
- Merge medio
- 16h 26m
- PR unite (30g)
- 21
Descrizione
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).
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia con l’esempio Python minimo nell’issue e confronta il comportamento con plotly.js issue #6199. Il lavoro è completato quando un singolo punto di data visualizza una barra visibile con una larghezza predefinita sensata, mentre le barre con più punti mantengono il comportamento attuale.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- data-visualization
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 38/100