[英]How to plot time series data in plotly?
When I plot my data with just the index the graph looks fine.当我 plot 我的数据只有索引时,图表看起来很好。 But when I try to plot it with a datetime object in the x axis, the plot gets messed up.但是,当我尝试在 x 轴上使用日期时间 object 对它进行 plot 时,plot 会变得一团糟。 Does anyone know why?有谁知道为什么? I provided the head of my data and also the two plots.我提供了我的数据的头部以及两个图。
import plotly.express as px
fig = px.line(y=data.iloc[:,3])
fig.show()
fig = px.line(y=data.iloc[:,3],x=data.iloc[:,0])
fig.show()
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.这可能是因为缺少日期,因为您有大约 180 个数据点,但您的第二个 plot 显示的数据跨度从 2014 年到 2019 年,这意味着它之间没有很多数据点,这就是为什么您的第二个图表看起来像这样。
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而不是 datetime 尝试将其转换为字符串,但它不会是一个时间序列,因为您将有很多丢失的日期
Here I have two solutions:在这里,我有两个解决方案:
import plotly.graph_objects as go
fig = go.Figure([go.Scatter(x=df.reset_index().index, y=df['close'])])
fig.show()
1277 is the index value and corresponding value is the closing price. 1277为指数值,对应值为收盘价。 Use.iloc() to find the x-axis value使用.iloc() 查找x轴值
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.