How to limit bar width with time-series axis

I have, for the last 24 hours, some events to be counted. I have some empty hours (no events).

I have two values for two hours. The rest should be considered as 0. Today is missing values, and the bar tends to go over the missing values, which is what I want to restrain.

Is there a way to restrict the width of the bars?

Hi @vvv.

I can’t reproduce this:

import plotly.graph_objects as go

data = [0, 1, 2, None, 3, None, None, 8]
fig = go.Figure(data=go.Bar(y=data))

newplot (11)

Adding code example, I would like to limit the bar width to 1 hour:

from pandas import DataFrame
from plotly.graph_objects import Figure
from import bar

dtf = DataFrame({"Hour": ["2023-07-10 17:00:00+08:00", "2023-07-10 21:00:00+08:00"], "size": [2, 5]})
fig = Figure(data=bar(dtf, x="Hour", y="size", text_auto=True))


you have a strange way of putting your Figure together mixing up and plotly.graph_objects

Here is how I would do this, the width parameter is what you are looking for. Since you are using a time axis, the width has to be specified in milliseconds:

from pandas import DataFrame
import plotly.graph_objects as go

dtf = DataFrame({"hour": ["2023-07-10 17:00:00+08:00", "2023-07-10 21:00:00+08:00"], "number": [2, 5]})
fig = go.Figure(go.Bar(x=dtf.hour, y=dtf.number, width=3_600_000))

mrep time axis