The tsplot
is a bit strange or at least strangly documented. If a dataframe is supplied to it, it assumes that there must be a unit
and a time
column present, as it internally pivots about those two. To use tsplot
to plot several time series you would therefore need to supply an argument to unit
as well; this can be the same as condition
.
sns.tsplot(df, time='hour', unit = "direction",
condition='direction', value='hourly_avg_count')
Complete example:
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
hour, direction = np.meshgrid(np.arange(24), np.arange(1,3))
df = pd.DataFrame({"hour": hour.flatten(), "direction": direction.flatten()})
df["hourly_avg_count"] = np.random.randint(14,30, size=len(df))
plt.figure(figsize=(12,8))
sns.tsplot(df, time='hour', unit = "direction",
condition='direction', value='hourly_avg_count')
plt.show()
Also worth noting that tsplot is deprecated as of seaborn version 0.8. It might thus be worth to use some other way to plot the data anyways.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…