5.直方图
histogram
import plotly.offline as of
import plotly.graph_objs as go
inport numpy as np
s1 = np.random.RandomState(1)
x = s1.randn(1000)
data = [
go.Histogram(
x = x,
histnorm = 'probability'
)
]
'''
histnorm ----> 如果我们设定histnorm = 'probability' 则纵坐标变为落入区间内的样本频率
默认状态下表示直方图纵坐标落入区间内的样本数目
'''
fig = go.Figure(data=data)
of.init_notebook_mode()
of.iplot(fig)
重叠垂直直方图
我们在说说重叠垂直直方图的绘制
需要在Layout中设置barmode属性,将其改为‘overlay’
如果我们不对其进行设置,会出现Plotly默认将两个直方图的柱状宽度强制变窄
以满足重叠部分的显示需求。
下面我们来看下,数据有Numpy随机生成
s1 = np.random.RandomState(1)
x0 = s1.randn(1000)
x1 = s1.chisquare(5, 1000)
trace1 = go.Histogram(
x = x0,
histnorm = 'pro