1

I'm plotting a timeseries graph (in 10 minute intervals) over 6 months on Python's Plotly and for some reason, it's graphing line between points at 12:00AM (ex. 01/02 12:00AM point to 01/03 12:00AM point, etc...). Please see the screenshot for reference... Here is the screenshot of it. screenshot:straight lines can be seen between 03-25 to 03-26 and 03-26 to 03-27 and so on...

import plotly
import plotly.express as px
import plotly.graph_objects as go

df = pd.read_csv('file',index_col = 'dates', parse_dates = True)
df['Without_year'] = df.index.strftime('%m-%d %H:%M:%S')
df['year'] = df.index.strftime('%Y')

fig = go.Figure()
fig.add_trace(go.Scatter(x = df_2019['Without_year'], y = df_2019['values'], name = '2019'))
fig.add_trace(go.Scatter(x = df_2020['Without_year'], y = df_2020['values'], name = '2020'))
Kevin Mayo
  • 1,089
  • 6
  • 19
  • What's the problem for you? Please explain it. – r-beginners Jul 21 '20 at 03:16
  • Plotly is adding extra lines between points. I added a screenshot link at the bottom of the post for reference. – iamfromjobland Jul 21 '20 at 03:27
  • I have a problem with the lines being drawn that I believe are not the original data. Is there a missing value or not, and is the data sorted in chronological order? The rest of the data would give us more answers. – r-beginners Jul 21 '20 at 03:51
  • Thanks for the reply. There are some missing values in the csv file but the lines are occurring even for periods when there is no missing data. It graphs from January 1st to June 20th and for some reason, the lines show up on 3/8, even though there are some missing data prior to 3/8. The data are chronological from January to June for 2019 and 2020 but 2020 data come first – iamfromjobland Jul 21 '20 at 04:04
  • Try deleting the records where the missing values exist. Check the sorting. Try to do the same thing in the graph library 'matplotlib'. If you change it and see an error, 'plotly' is the issue. Let's try to isolate them one by one. – r-beginners Jul 21 '20 at 04:10
  • 1
    Actually, when I was trying to sort it chronologically, I noticed that some dates were duplicated. Once I deleted them, the lines were gone. Thank you! – iamfromjobland Jul 21 '20 at 04:23
  • That's good to hear, Enjoy! – r-beginners Jul 21 '20 at 04:45
  • Sorting the data which is used in the x-axis of the graph, seems to solve this issue. Please refer this solution for a similar problem, it solved the issue for me. https://stackoverflow.com/a/63232662/14033165 – Sash7 Apr 11 '22 at 12:49

0 Answers0