Marine ship does not show data

I'm trying to use the seabed to make a simple tsplot, but for reasons I don't understand, nothing appears 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 you provide a tsplot with multiple data points at a time, but doesn't that just work if you only supply one?

I know matplotlib can be used to do this quite easily, but I wanted to use marine boats for some of my other functions.

+3


source to share


2 answers


You are missing the individual unit

s. When using a data frame, the idea is that multiple time series have been recorded for the same unit

, which can be individually identified in the data frame. The error is then computed based on the different unit

s.

So, for one series, you can make it work 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')

      



To see how the error is calculated, take a 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')

      

+2


source


You can use set_index

for index

from column time

and then build Series

:

df = pd.DataFrame({'value': np.random.rand(31), 'time': range(31)})
df = df.set_index('time')['value']
ax = sns.tsplot(data=df)
sns.plt.show()

      



graph

+1


source