[英]Plotting data by year over year using plotly
I have a data look like this:-我的数据如下所示:-
Month Year Value
Jan 2015 2.8
Jan 2015 2.0
Mar 2016 0.9
Feb 2015 3.1
Mar 2016 4.2
Feb 2015 2.1
Mar 2016 2.3
Feb 2015 1.1
Apr 2016 1.3
Apr 2016 0.5
Now I want to plot line chart, but by using this code, I am getting this output.现在我想要 plot 折线图,但是通过使用这个代码,我得到了这个 output。 below
以下
Code I have used:-我用过的代码:-
df = rslt_bb.sort_values(by='Year')
trace = go.Scatter(
x = df["Year"],
y = df["Value"],
mode='markers+lines'
)
layout = go.Layout(
#title='Distribution by year',
xaxis=dict(title='Year'),
yaxis=dict(title='Value'),
showlegend=True
)
fig = dict(data=[trace], layout=layout)
offline.iplot(fig)
I want the plotting should be like not aggregated all common year in the same line, I want spreaded.我希望绘图应该像不在同一行中聚合所有常见年份一样,我希望分散。 All year, single data should be visible separately, like this way below,
全年,单个数据应单独可见,如下所示,
You need to crate a datetime
object for plotting a Time Series
.您需要创建一个
datetime
时间 object 来绘制Time Series
。 So instead of所以而不是
x = df["Year"]
use利用
# import pandas as pd
x = pd.to_datetime(df.Year*100+df.Month, format='%Y%m')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.