Introduction:
Your provided data sample is an image, and not very easy to work with, so I'm going to use some sampled random time series to offer a suggestion. The variables in your datasample don't match the ones you've used in px.Scatter
either by the way.
I'm on plotly version '4.2.0'
and unable to reproduce your issue. Hopefully you'll find this suggestion useful anyway.
Using data structured like this...
Timestamp Position_type value
145 2020-02-15 value3 86.418593
146 2020-02-16 value3 78.285128
147 2020-02-17 value3 79.665202
148 2020-02-18 value3 84.502445
149 2020-02-19 value3 91.287312
...I'm able to produce this plot...
...using this code:
# imports
from plotly.subplots import make_subplots
import plotly.graph_objs as go
import pandas as pd
import numpy as np
# data
np.random.seed(123)
frame_rows = 50
n_plots = 2
frame_columns = ['V_'+str(e) for e in list(range(n_plots+1))]
df = pd.DataFrame(np.random.uniform(-10,10,size=(frame_rows, len(frame_columns))),
index=pd.date_range('1/1/2020', periods=frame_rows),
columns=frame_columns)
df=df.cumsum()+100
df.iloc[0]=100
df.reset_index(inplace=True)
df.columns=['Timestamp','value1', 'value2', 'value3' ]
varNames=df.columns[1:]
# melt dataframe with timeseries from wide to long format.
# YOUR dataset seems to be organized in a long format since
# you're able to set color using a variable name
df_long = pd.melt(df, id_vars=['Timestamp'], value_vars=varNames, var_name='Position_type', value_name='value')
#df_long.tail()
# plotly time
import plotly.io as pio
import plotly.express as px
#pio.renderers = 'jupyterlab'
fig = px.scatter(data_frame=df_long, x='Timestamp', y='value', color='Position_type')
#fig = px.line(data_frame=df_long, x='Timestamp', y='value', color='Position_type')
fig.show()
If you change...
px.scatter(data_frame=df_long, x='Timestamp', y='value', color='Position_type')
...to...
fig = px.line(data_frame=df_long, x='Timestamp', y='value', color='Position_type')
...you'll get this plot instead:
No trendlines as far as the eye can see.
Edit - I think I know what's going on...
Having taken a closer look at your figure, I've realized that those lines are not trendlines. A trendline doesn't normally start at the initial value of a series and end up at the last value of the series. And that's what happening here for all three series. So I think you've got some bad or duplicate timestamps somewhere.