Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

for each unique column value, plot line plot with multiple hues on different columns

My pandas dataframe is like this

name,id,score1,score2,score3
ax,1,32,43,32
sy,1,34,22,22
ax,2,22,6,8
ax,3,10,5,4
bz,1,22,2,2
sy,2,10,1,0
bz,2,9,8,1

How can I create a line plot in seaborn for each unique name where id would be the x-axis, and the y-axis would be ‘score1’, ‘score2’, and ‘score3’, and the hue would be ‘score1’, ‘score2’, and ‘score3’?

sns.lineplot(data=flights, x="year", y="passengers", hue="month")

I wonder how do u handle the scenario where the hue is on different columns on a pandas dataframe? In my case, that is ‘score1’, ‘score2′, score3’

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Thanks!

>Solution :

What you want is unclear, but you can always melt your data before plotting:

import seaborn as sns
sns.lineplot(data=df.melt(['name', 'id'], var_name='score', value_name='value'),
             x='id', y='value', style='name', hue='score')

Output:

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading