I am looking for a way to add a horizontal line for each trace, with the mean of the trace as value.
I have looked at adding a line using โshapeโ in the layout, but that would be for the entire graph. I am looking to have this line for each trace.
My legend would be the same: trace 1 and trace 2, but clicking on trace 1 would highlight my trace + the new trace โmeanโ.
I am using this code:
import datetime
import numpy as np
import pandas as pd
a = np.array([1,2,3,4,5])
b = np.array([1.2,2.4,3.6,4.5,5.2])
dates = [datetime.date.today() - datetime.timedelta(1),datetime.date.today() -
datetime.timedelta(2),datetime.date.today() - datetime.timedelta(3),datetime.date.today() -
datetime.timedelta(4),datetime.date.today() - datetime.timedelta(5)]
data_plot = []
data_plot.append(go.Scatter(
x=dates,
y=a,
mode='line',
))
data_plot.append(go.Scatter(
x=dates,
y=b,
mode='line',
))
layout_plot = go.Layout(
title='plotly_forum')
fig = go.Figure(data=data_plot, layout=layout_plot)
py.plot(fig)