Home > front end >  Overflow bin is not showing up in plotly/python?
Overflow bin is not showing up in plotly/python?

Time:10-21

Here is my code:

import plotly.graph_objects as go
import numpy as np
a = dataset['reportNum'].to_numpy()

np.random.seed(1)

hist, bins = np.histogram(a, bins=[0,500,1000,1500,2000,2500,3000,3500,4000,4500,5000,5500,6000,6500,7000,7500,8000,15000])
    
fig = go.Figure(go.Bar(x=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17],y=hist))

fig.update_xaxes(tickvals=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17], ticktext=['(0,100]','(100,500]','(500,1000]','(1000,1500]','(1500,2000]',
'(2000,2500]','(2500,3000]','(3000,3500]','(3500,4000]','(4000,4500]','(4500,5000]','(5000,5500]','(5500,6000]',
'(6000,6500]','(6500,7000]','(7000,7500]','(7500,8000]','>8000'])
fig.update_layout(bargap=0)
fig.show()

However, I am getting this graph:

enter image description here

I want the overflow bin of '>8000' to show up in my histogram

CodePudding user response:

You should add 100 to the bins in the np.histogram

np.histogram(a, bins=[0,100,500,.....])  #<----- add the 100 

enter image description here

  • Related