Black Lives Matter. Please consider donating to Black Girls Code today.

How do i plot vertical line over a timeseries curve in plotly

Hi,
I have two traces as below trace1 and trace2. I want to make a vertical line at a particular x value which is in events_i[0].
How do i plot a vertical line at a particular x point, possibly multiple X points which will be from an array which span the entire plot vertically.
I tried using shapes but it is not working.

trace1 = go.Scatter(
x = df123.index,
y = df123[‘1_RSRP0’],
name = ‘1_RSRP0’,
xaxis=‘x1’,
mode =‘markers’
)

trace2 = go.Scatter(
x = df123.index,
y = df123[‘2_RSRP0’],
name = ‘2_RSRP0’,
xaxis=‘x1’,
mode =‘markers’
)

data = [trace0,trace1,trace2]

layout = Layout(
title=“RSRP v time”,
yaxis=YAxis(
title = “db”
),
xaxis=XAxis(
title= ‘time’
)

)

fig = Figure(data=data,layout=layout)

iplot(fig)

I am able to plot it using cufflinks with below command, however i wish to do it with plotly , as I have many more customizations to add on plot which are not available in cufflinks yet.

df123.iplot(x = ‘time’ , y = [‘P_RSRP0’ , ‘1_RSRP0’,‘2_RSRP0’ ] , mode =‘lines+markers’,vline = events_i[0])

Can someone please help ?

-Thx
Jay

@joshijay655,
If you set in layout['yaxis'] the range=[c, d], then a vertical line through a point of coordinates (a,b) is defined as a scatter plot with mode='lines' and

  x=[a, a],
  y=[c ,d]

Any way to do this over subplotss ? Like line spanning all subplots ?

@joshijay655 You make lines that span subplots with shapes: https://plot.ly/python/shapes/

Hi Jack,

If I make lines with shapes, they do span the subplots , however is there any way to add hover text over those lines ?

-Thanks
Jay

Is there any way to add hover text over those lines ?

Not really. You could add transparent (opacity=0) scatter points behind the line in each subplot. This is the only way I’ve seen people add hover text to shapes.

Thanks need to try this, pretty inconvenient though