Creating a histogram with a custom bin size

I have some dummy data here in the form of a list : [30.2049, 51.3693, 51.8094, 30.5573, 56.8151, 45.9166, 56.2858, 55.4125, 72.8778, 39.7996, 34.8203, 36.8362, 39.9959, 54.7995, 52.5158, 40.6841, 61.3939, 48.5818, 41.4944, 71.5607, 49.0913, 57.7985, 70.2787, 45.2226, 55.7449, 69.0475, 33.9624, 51.3384, 53.1948, 46.1682, 66.5202, 37.0265, 48.0182, 44.2164, 56.9336, 69.7961, 48.6728, 44.5923, 33.2164, 41.8337
56.7741, 35.6030, 33.9237, 41.5178, 50.4453, 29.0570, 33.0124, 58.6281, 39.2005, 42.9119]

I want to reproduce this histogram below which is made using this data in plotly python:
Example

Right now, the curves as well as LSL & USL can be ignored (not got anything to do with the histogram). Is there a way to construct the plot and getting the bin width of the histogram as I need it later on to produce the other curves. Also is there a way to get those black outlines in each bar ?

Any help is appreciated.

Hi @ULTRA, I just made this as a possible solution (with a slider to choose bin size). I hope it helps. Feel free to check also the plotly documentation, there are often very useful examples!

import plotly.graph_objs as go
import plotly.figure_factory as ff

import numpy as np

data  = [30.2049, 51.3693, 51.8094, 30.5573, 56.8151, 45.9166, 56.2858, 55.4125, 72.8778, 
         39.7996, 34.8203, 36.8362, 39.9959, 54.7995, 52.5158, 40.6841, 61.3939, 48.5818, 
         41.4944, 71.5607, 49.0913, 57.7985, 70.2787, 45.2226, 55.7449, 69.0475, 33.9624, 
         51.3384, 53.1948, 46.1682, 66.5202, 37.0265, 48.0182, 44.2164, 56.9336, 69.7961, 
         48.6728, 44.5923, 33.2164, 41.8337,56.7741, 35.6030, 33.9237, 41.5178, 50.4453, 
         29.0570, 33.0124, 58.6281, 39.2005, 42.9119]  

hist_data = [data]
group_labels = ['distplot']
f = ff.create_distplot(hist_data, group_labels, bin_size=5, show_rug=False)
fig = go.FigureWidget(f)
fig.data[0].marker.line =  dict( color = 'black',width = 2)
fig.data[1].line.color = 'red'
fig.layout.sliders = [dict(
                active = 4,
                currentvalue = {"prefix": "bin size: "},
                pad = {"t": 20},
                steps = [dict(label = i, method = 'restyle',  args = ['xbins.size', i]) for i in range(1,20)]
            )]
fig

1 Like

Thanks for the help.