Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

matplotlib - How do I plot multiple time series grouped by different colours?

I am trying to have a single graph displaying a 10 series. These are divided in group such as this simple example :

            Group A | Group B
   time(h)  S1 S2 S3   S4 S5 S6
     0      1  3   1   3  4  5
     24     2  1   3   4  2  1
     48     3  2   2   1  2  2

How can I add these 6 series in a single graph and categorise their group A/B by colour ?

Thank you so much!

question from:https://stackoverflow.com/questions/65832228/how-do-i-plot-multiple-time-series-grouped-by-different-colours

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can try seaborn:

import seaborn as sns

sns.lineplot(data=df.stack(level=[0,1]).reset_index(name='value'),
             x='time', y='value', hue='level_1', style='level_2' 
            )

And you would get:

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...