Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Seaborn tsplot not showing data

I'm trying to use seaborn to make a simple tsplot, but for reasons that aren't clear to me nothing shows up when I run the code. Here's a minimal example:

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

Usually tsplot you supply multiple data points for each time point, but does it just not work if you only supply one?

I know matplotlib can be used to do this pretty easily, but I wanted to use seaborn for some of its other functionality.

like image 905
Kewl Avatar asked Jul 02 '26 09:07

Kewl


1 Answers

You are missing individual units. When using a data frame the idea is that multiple timeseries for the same unit have been recorded, which can be individually identifier in the data frame. The error is then calculated based on the different units.

So for one series only, you can get it working again like this:

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

Just to see how the error is computed, look at this example:

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')
like image 100
languitar Avatar answered Jul 03 '26 22:07

languitar