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’

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

Leave a Reply