Multi line chart with marine tsplot

I want to create a smoothed line chart using matplotlib and seaborn.

This is my dataframe df:

hour    direction    hourly_avg_count
0       1            20
1       1            22
2       1            21
3       1            21
..      ...          ...
24      1            15
0       2            24
1       2            28
...     ...          ...

The line chart should contain two lines, one for directionis 1, the other for directionis 2. The X axis hour, and the Y axis hourly_avg_count.

I tried this, but I do not see the lines.

import pandas as pd
import seaborn as sns
import matplotlib
import matplotlib.pyplot as plt

plt.figure(figsize=(12,8))
sns.tsplot(df, time='hour', condition='direction', value='hourly_avg_count')
+2
source share
2 answers

tsplot , , . , , unit time, . tsplot , unit; , condition.

sns.tsplot(df, time='hour', unit = "direction", 
               condition='direction', value='hourly_avg_count')

:

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()

enter image description here

, tsplot 0.8. , , - .

+6

. - , , , .

import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np

df1 = pd.DataFrame({
"hour":range(24),
"direction":1,
"hourly_avg_count": np.random.randint(25,28,size=24)})

df2 = pd.DataFrame({
"hour":range(24),
"direction":2,
"hourly_avg_count": np.random.randint(25,28,size=24)})

df = pd.concat([df1,df2],axis=0)
df['unit'] = 'subject'

plt.figure()
sns.tsplot(data=df, time='hour', condition='direction',
unit='unit', value='hourly_avg_count')

enter image description here

+1

Source: https://habr.com/ru/post/1690090/


All Articles