python - Seaborn tsplot 不显示数据

标签 python pandas seaborn

我正在尝试使用 seaborn 制作一个简单的 tsplot,但由于我不清楚的原因,当我运行代码时没有任何显示。这是一个最小的例子:

import numpy as np
import seaborn as sns
import pandas as pd

df = pd.DataFrame({'value': np.random.rand(31), 'time': range(31)})

ax = sns.tsplot(data=df, value='value', time='time')
sns.plt.show()

enter image description here

通常 tsplot 为每个时间点提供多个数据点,但如果只提供一个就不行吗?

我知道可以使用 matplotlib 非常轻松地完成此操作,但我想使用 seaborn 来实现它的一些其他功能。

最佳答案

您缺少个别单位。使用数据框时,想法是记录了同一 unit 的多个时间序列,它们可以在数据框中作为单独的标识符。然后根据不同的 unit 计算误差。

所以对于一个系列,你可以像这样让它再次工作:

df = pd.DataFrame({'value': np.random.rand(31), 'time': range(31)})
df['subject'] = 0
sns.tsplot(data=df, value='value', time='time', unit='subject')

为了了解错误是如何计算的,请看这个例子:

dfs = []
for i in range(10):
    df = pd.DataFrame({'value': np.random.rand(31), 'time': range(31)})
    df['subject'] = i
    dfs.append(df)
all_dfs = pd.concat(dfs)
sns.tsplot(data=all_dfs, value='value', time='time', unit='subject')

关于python - Seaborn tsplot 不显示数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42955079/

相关文章:

pdf - Seaborn 热图到 .pdf 的速度非常慢。这是正常的吗?

Python sha512 安全

python - 在多列中查找匹配值并返回匹配的列头

python - 在 python3 'TypeError: descriptor ' __subclasses_ _' of ' 类型中导入 Pandas 时出错 object needs an argument'

python - 如何使用seaborn.objects显示所有x-tick标签

pandas - python : Best way to visualize dict of dicts

Python Spark 如何使用 RDD API 按组查找累计和

python - 使用 python 实现 Json 的 Excel

python - 需要重置整个postgres数据库,想要备份数据库中的表

python - 如何根据 pandas 数据框中的频率创建词云