1

When I plot my data with just the index the graph looks fine. But when I try to plot it with a datetime object in the x axis, the plot gets messed up. Does anyone know why? I provided the head of my data and also the two plots.

enter image description here

import plotly.express as px
fig = px.line(y=data.iloc[:,3])
fig.show()

enter image description here

fig = px.line(y=data.iloc[:,3],x=data.iloc[:,0])
fig.show()

enter image description here

2 Answers 2

1

It is probably because of missing dates as you have around 180 data points but your second plot shows data spans from 2014 to 2019 that means it does not have many data points in between that's why your second graph looks like that.

Instead of datetime try plotting converting it into string but then it will not be a time series as you will have many missing dates

Sign up to request clarification or add additional context in comments.

Comments

0

Here I have two solutions:

  1. Use reset_index() function to get rid off the missing dates but it just explains the chart but x-axis values don't provide date information anymore. Heres an example: This is the data frame and I want to plot the chart between time and closing price

enter image description here

import plotly.graph_objects as go
fig = go.Figure([go.Scatter(x=df.reset_index().index, y=df['close'])])
fig.show()

enter image description here

1277 is the index value and corresponding value is the closing price. Use .iloc() to find the x-axis value enter image description here

  1. Convert x-axis value to datetime object Follow this link: https://stackoverflow.com/a/51231209/10277042

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.