I am using histogram to show data from a database in monthly bins. The code looks like
fig_in_out = px.histogram(
disk_df,
x="date",
y="disk",
color="Kind",
nbins=len(Month_list),
barmode="relative",
histfunc="sum",
)
fig_in_out.update_layout(bargap=0.2)
where Month_list
is enumerating all month in YYYY-MM format covered by the range of dates from a start point until today. βkindβ has two possible values (one kind is positive and the other is negative, which is why I have barmode="relative"
).
By setting nbins
to the number of months I was hoping that my histogram would show one bar per months for each kind. And it does behave like that some of the time.
At some point during the month, the bars started to span two months instead of one. The first time it happened I doubled nbins
thinking that may be it needed to take into account the number of colors. Then later, the bars started to show fortnights instead of months and I changed nbins
back. And some time later I am back with bars covering two months instead of one. And on it loops.
I am guessing it has something to do with the number of data points in my series or possibly whether it is the first half of the month or not. But I really would like to figure out something that stays consistent over time and that I do not need to change every so often.