2

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 : enter image description here

ntg
  • 12,950
  • 7
  • 74
  • 95
  • 1
    Please replace `[code to print histogram using plotly here....]` with your own attempts at doing what you're asking for here. – vestland Mar 10 '21 at 18:15
  • This essentially says please replace your question with the best answer you be got so far :) That's cool, but the problem is by posting a 'good engough' working answer, there may be a better answer that I have not, and will never find... – ntg Mar 10 '21 at 18:38
  • 1
    Maybe... At least those who are seeking to answer your question have a better idea of what you're looking for now. If a better approach *does* exist, I believe you've increased your chances considerably of finding it by showing exactly what you just did. I can't guarantee that *I* will be the one to do so, but I will at least give it a try. But are you happy with what you have so far regarding specifying the bin sizes? – vestland Mar 10 '21 at 19:05

0 Answers0