I need to create the histogram in plotly using python 3.0, so this question is specific to plotly.
I want to have specific bin sizes, manually defined as a list for my Histogram. Example toy code
hours_worked = [1.1,1,1,2,10,11,12,50,73] #some data
bins = np.concatenate([
np.arange(12), # first 12 hrs
12+np.arange(6)*2, # then 2hrs periods up to 1 day
np.arange(1,7)*24, # then days up to week and cut it off...
])
[code to print histogram using plotly here....]
[edit based on comment and after some time of coding...] So far, the best solution I can see is going through numpy.histogram doing something like:
gap=.9
h = np.histogram(hours_worked,bins=list(bins))
bar_widths = (bins[1:]-bins[:-1])
bar_centers = (bins[1:]+bins[:-1])/2
bar_height = h[0]/bar_widths
fig = go.Figure(data=[go.Bar(
x=bar_centers,
y=bar_height,
width=bar_widths*gap
)])
which gives the pic bellow. May need to consider if the figure need normalization to avoid being misleading, and making a function though :