【问题标题】:Use seaborn to make time series plot instead of pandas.dataframe.plot使用 seaborn 制作时间序列图而不是 pandas.dataframe.plot
【发布时间】:2020-02-15 04:12:59
【问题描述】:

我知道了。数据框:

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

我可以这样绘制:

df.plot()

我如何在 seaborn 中做到这一点?我正在尝试这个,但它不起作用。请注意,我不想明确指定列名,因为列数比这个玩具示例大得多。

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

【问题讨论】:

  • df.plot()import seaborn 之后不起作用?
  • 确实如此,但是如何让 tsplot 工作?
  • 你想要这样的东西吗? sns.tsplot(data=df.T.values, time=df.index)
  • 感谢@mwaskom,感谢您提供的优秀图书馆!

标签: python pandas matplotlib seaborn


【解决方案1】:

如果我理解正确,我的建议是使用 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()

【讨论】:

    猜你喜欢
    • 2017-10-16
    • 2014-10-31
    • 2015-05-19
    • 2014-05-12
    • 1970-01-01
    • 2020-06-06
    • 2016-09-07
    • 2018-10-23
    • 2021-01-29
    相关资源
    最近更新 更多