Multi-line chart with seaborn tsplot

前端 未结 2 1409
故里飘歌
故里飘歌 2020-12-11 22:25

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

This is my dataframe df:

hour    direction    hourly_avg_count
0            


        
2条回答
  •  悲哀的现实
    2020-12-11 22:51

    Try adding a dummy unit column. The first parts is to create some synthetic data, so please ignore.

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

提交回复
热议问题