Timeseries plot with min/max shading using Seaborn

后端 未结 3 2058
隐瞒了意图╮
隐瞒了意图╮ 2020-12-30 11:08

I am trying to create a 3-line time series plot based on the following data , in a Week x Overload graph, where each Cluster is a different line.

I have multiple obs

3条回答
  •  星月不相逢
    2020-12-30 11:25

    I finally used the good old plot with a design (subplots) that seems (to me) more readable.

    df = pd.read_csv('TSplot.csv', sep='\t', index_col=0)
    # Compute the min, mean and max (could also be other values)
    grouped = df.groupby(["Cluster", "Week"]).agg({'Overload': ['min', 'mean', 'max']}).unstack("Cluster")
    
    # Plot with sublot since it is more readable
    axes = grouped.loc[:,('Overload', 'mean')].plot(subplots=True)
    
    # Getting the color palette used
    palette = sns.color_palette()
    
    # Initializing an index to get each cluster and each color
    index = 0
    for ax in axes:
        ax.fill_between(grouped.index, grouped.loc[:,('Overload', 'mean', index + 1)], 
                        grouped.loc[:,('Overload', 'max', index + 1 )], alpha=.2, color=palette[index])
        ax.fill_between(grouped.index, 
                        grouped.loc[:,('Overload', 'min', index + 1)] , grouped.loc[:,('Overload', 'mean', index + 1)], alpha=.2, color=palette[index])
        index +=1
    

提交回复
热议问题