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.
you have a strange way of putting your Figure together mixing up plotly.express 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))
fig.show()