i have two pandas series:
x=[59281.021432, 59281.063095, 59281.104768, 59283.188094, 59283.313102]
x=pd.Series(x)
y=[1.0, 2.1, 3.3, 12.1, 12.3]
y=pd.Series(y)
which have the same size. When i plot the graph with plotly i don't see the gaps:
fig = go.Figure(layout=go.Layout(xaxis_title='MJD [days]', yaxis_title='value'))
fig.add_trace(go.Scatter(x=x, y=y, type = 'scatter', mode = 'lines'))
What i would like to see is the same graph, but with the gap without the line. Is it possible? I see that i should put a None character into the serie x between 59281.104768 and 59283.188094, but how?
i have tried this code to obtain the lower and the upper boudaries, but i do not know how to complete the series adding None values:
delta = x[1] - x[0]
lowerBounds = (x+delta)[:-1]
upperBounds = (x-delta)[1:]
lowerBounds=lowerBounds.to_numpy()
upperBounds=upperBounds.to_numpy()
mask = lowerBounds<=upperBounds
upperBounds, lowerBounds = upperBounds[mask], lowerBounds[mask]
Thank you
I suspect that this is what you're aiming to do:
If that's the case then I would organize your series in a dataframe, subset the dataframe according to a defined gap
, and then use add_trace
for each subset.
import plotly.graph_objects as go
import pandas as pd
x=[59281.021432, 59281.063095, 59281.104768, 59283.188094, 59283.313102]
x=pd.Series(x)
y=[1.0, 2.1, 3.3, 12.1, 12.3]
y=pd.Series(y)
df = pd.DataFrame({'x':x,
'y':y})
gap = 12
fig = go.Figure(layout=go.Layout(xaxis_title='MJD [days]', yaxis_title='value'))
# fig.add_trace(go.Scatter(x=x, y=y, type = 'scatter', mode = 'markers'))
fig.add_trace(go.Scatter(x=df[df['y']>gap]['x'],
y=df[df['y']>gap]['y'], mode = 'lines',
line=dict(color='blue')))
fig.add_trace(go.Scatter(x=df[df['y']<gap]['x'],
y=df[df['y']<gap]['y'], mode = 'lines',
line=dict(color='blue')))
fig.show()