我需要在Plotly中绘制两个直方图,每个直方图都有一条绘制在平均值处的线,并显示平均值标签。目前我的代码可以绘制两个直方图,但我不知道如何添加平均线和标签。有什么建议吗?
import numpy as np
import random
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
import plotly.graph_objs as go
init_notebook_mode() # run at the start of every ipython notebook
a = np.random.normal(1500, 100, 1000)
b = np.random.normal(1500, 150, 1000)
trace1 = go.Histogram(
x=a,
opacity=0.75,
histnorm='probability',
name='> 180 t/h'
)
trace2 = go.Histogram(
x=b,
opacity=0.75,
histnorm='probability',
name='< 160 t/h',
yaxis='y2'
)
data = [trace1, trace2]
layout = go.Layout(
title='title',
barmode='overlay',
xaxis=dict(
title=''
),
yaxis=dict(
title='Normalized Frequency < 160 t/h'
),
yaxis2=dict(
title='Normalized Frequency > 180 t/h',
anchor='free',
overlaying='y',
side='right',
position=1
)
)
fig = go.Figure(data=data, layout=layout)
iplot(fig)