Best plot for 2 categorical and 1 quantitative variable over time matplotlib

Currently, I have a table in the form:

created_date    type    category    count
2020/10/10       A         C1        2
                           C2        3
                 B         C1        2
                           C2        8
2020/10/11       A         C1        3
... and so on

So basically I have a df grouped by three variables i.e. time, type, and category. What I want is a way to plot it into a single graph (if possible) with the maximum amount of information.

1 answer

  • answered 2021-07-27 18:39 mozway

    You can test seaborn.lineplot

    import seaborn as sns
    sns.lineplot(data=your_df, x='created_date', y='count', hue='type', style='category')
    

    Using this dummy data as input:

    df1 = pd.DataFrame({'created_date': np.repeat(pd.date_range('2020-10-10', '2020-12-31'), 4),
                        'type': np.tile(np.repeat(['A', 'B'], 2), 83),
                        'category': np.tile(['C1', 'C2'], 2*83),
                        'count': np.sin(np.arange(4*83)/80+np.tile([0,1,0,1], 83))+np.tile([0,0.2,0.4,0.5], 83)
                        
                       })
    
      created_date type category     count
    0   2020-10-10    A       C1  0.000000
    1   2020-10-10    A       C2  1.048159
    2   2020-10-10    B       C1  0.424997
    3   2020-10-10    B       C2  1.361136
    4   2020-10-11    A       C1  0.049979
    5   2020-10-11    A       C2  1.073575
    6   2020-10-11    B       C1  0.474930
    7   2020-10-11    B       C2  1.385468
    8   2020-10-12    A       C1  0.099833
    9   2020-10-12    A       C2  1.096808
    ...
    

    Here is how it looks:

    lineplot

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum