简体   繁体   English

使用 seaborn 制作时间序列图而不是 pandas.dataframe.plot

[英]Use seaborn to make time series plot instead of pandas.dataframe.plot

I have the foll.我有办法。 dataframe:数据框:

df
          A         R
0    0.000000     0.000000
1  176.069152   544.511391
2  352.338584   965.989678
3  528.824516  1387.844940
4  705.510351  1809.956118

I can plot it like this:我可以这样绘制:

df.plot()

How can I do this in seaborn?我怎样才能在 seaborn 中做到这一点? I am trying this, but it does not work.我正在尝试这个,但它不起作用。 Please note that I do not want to explicitly specify column names, since the number of columns is much larger than this toy example.请注意,我不想明确指定列名,因为列数比这个玩具示例大得多。

import seaborn as sns
sns.tsplot(data=df, time=df.index, value=df)

If I understood it right, my recommendation is to do it with matplotlib like this:如果我理解正确的话,我的建议是像这样用 matplotlib 来做:

import matplotlib.pyplot as plt
x = df.index

fig, ax = plt.subplots()
for name in df.columns.values:
    ax.plot(x, df[name], label=name)
ax.legend()
plt.show()

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM