0

I have the following data (two dataframes):

  df
           Name Surname P   R   F   
        0   B   N   0.41    0.76    0.53
        1   B   L   0.62    0.67    0.61
        2   B   SV  0.63    0.53    0.52
        3   B   SG  0.43    0.61    0.53
        4   B   R   0.81    0.51    0.53
        5   T   N   0.32    0.82    0.53
        6   T   L   0.58    0.69    0.62
        7   T   SV  0.67    0.61    0.64
        8   T   SG  0.53    0.63    0.57
        9   T   R   0.74    0.48    0.58

and

data = [['B','N',0.41,0.72,0.51], 
['B','L',0.66,0.67,0.62],
['B','SV',0.63,0.51,0.51],
['B','SG',0.44,0.63,0.51],
['B','R',0.81,0.51,0.62],
['T','N',0.33,0.80,0.47],
['T','L',0.58,0.61,0.63],
['T','SV',0.68,0.61,0.64],
['T','SG',0.53,0.63,0.57],
['T','R',0.74,0.48,0.58]]

df1 = pd.DataFrame(data, columns = ['Name','Surname','P','R','F']) 

I would need to compare, eventually in separate plots, the values of P, R and F based on Name and Surname.

I tried as follows:

  ax = df[['P']].plot()
    l = ax.get_lines()
    df1[['P']].plot(ax=ax, linestyle='--', color=(i.get_color() for i in l))  

But the problem is that the x-values are not Surname and the information on Name misses (for example with a legend or using different colours).

Any help on this would be appreciated.

2
  • "based on Name and Surname" how would that look like. Commented Dec 25, 2020 at 19:34
  • I would like to have on the x-axis the Surname values (L, SV, SG, ...). I should have two colours for distinguishing data based on Name (B and T) Commented Dec 25, 2020 at 19:36

1 Answer 1

1

You can use seaborn to plot the two lines while looping through the value columns:

fig = plt.figure(figsize=(8,8))
for n, col in enumerate(['P','R','F'], start=1):
    ax = plt.subplot(2,2,n)
    sns.lineplot(data=df1, x='Surname', y=col, hue='Name')

Output: enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.