时间序列的简单 tsplot [英] Simple tsplot for timeseries

查看:46
本文介绍了时间序列的简单 tsplot的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下数据框:

 日期组计数0 2015-01-12 类别 1 271 2015-01-19 类别1 22 2015-01-26 类别1 313 2015-02-02 类别1 204 2015-02-09 类别1 245 2015-02-16 类别1 166 2015-02-23 类别1 187 2015-03-02 类别1 158 2015-03-09 Category1 299 2015-03-16 类别1 610 2015-03-23 类别1 1911 2015-03-30 类别1 2712 2015-04-06 类别1 613 2015-04-07 类别1 714 2015-04-13 类别1 2515 2015-04-20 类别1 9

我想使用 seaborn 绘制一个简单的时间序列.只是 Y 轴上计数的折线图,X 轴上有日期,例如:

我认为它会很简单:sns.tsplot(data=df, time=df['Date'], value=df['count'])sns.tsplot(data=df, time='Date', value='count') 并遵循

I have below dataframe:

    Date    group   count
0   2015-01-12 Category1    27
1   2015-01-19 Category1    2
2   2015-01-26 Category1    31
3   2015-02-02 Category1    20
4   2015-02-09 Category1    24
5   2015-02-16 Category1    16
6   2015-02-23 Category1    18
7   2015-03-02 Category1    15
8   2015-03-09 Category1    29
9   2015-03-16 Category1    6
10  2015-03-23 Category1    19
11  2015-03-30 Category1    27
12  2015-04-06 Category1    6
13  2015-04-07 Category1    7
14  2015-04-13 Category1    25
15  2015-04-20 Category1    9

I want to plot a simple timeseries using seaborn. Just a line chart of count on the Y-Axis, with Date on the X-axis something like this just for example:

I thought it would be as simple as: sns.tsplot(data=df, time=df['Date'], value=df['count']) or sns.tsplot(data=df, time='Date', value='count') and following the tsplot() documentation I can't quite get this simple line of code. The datatypes seem fine, but what am i missing here?:

#df.dtypes
Date     datetime64[ns]
group            object
count             int64

Side note, does anyone know why tsplot() is being deprecated for? (beyond the vague definition in the docs)

解决方案

I guess tsplot is deprecated because people tend to think it would be useful for plotting timeseries - which isn't the case. Of course you may use it, see e.g. this question, but I would recommend simply plotting the data as a line plot:

ax = df.plot(x="Date", y="count")
ax.figure.autofmt_xdate()

这篇关于时间序列的简单 tsplot的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆