1

I have two numpy-lists (from the same pandas df) where x is the reference number (identical for both datasets) and y is the variable to compare . I now want to examine two data sets for their difference in the y variable. They should be displayed in different colors in the same diagram. The seaborn library was used to add a regression line.

sns.lmplot(x="common_ln_code", 
           y="dif_jac_erl_ev11", 
           data=ethnologue_common,
           height=10)

sns.lmplot(x="common_ln_code", 
           y="dif_jac_erm_ev22", 
           data=ethnologue_common,
           height=10)

plt.xlabel("language code")
plt.ylabel("Differenz Jaccardindex")
plt.title("Large vs. Medium_river")
plt.legend()
plt.show()

I tried this. but now I have two seperate plots. One for y="dif_jac_erl_ev11", and one for y="dif_jac_erm_ev22". I d like to have one figure to compare them

Aaron
  • 11
  • 3

1 Answers1

0

You have to use hue parameter of sns.lmplot after reshaping your dataframe:

data = ethnologue_common.melt(id_vars='common_ln_code',
                              var_name='dif_jac_erm',
                              value_name='ev')
sns.lmplot(x='common_ln_code',
           y="ev",
           hue='dif_jac_erm',
           data=data,
           height=10)
plt.show()

Output:

enter image description here

Input:

>>> ethnologue_common
    common_ln_code  dif_jac_erm_ev11  dif_jac_erm_ev22
0                9                 5                 5
1                3                 7                 9
2                2                 2                 2
3                7                 1                 3
4                3                 6                 2
5                8                 0                 6
6                2                 6                 2
7                3                 2                 9
8                9                 1                 1
9                5                 5                 3
10               0                 1                 8
11               7                 8                 0
12               8                 4                 3
13               6                 1                 4
14               2                 0                 9
15               9                 7                 2
16               7                 3                 7
17               6                 6                 6
18               3                 1                 4
19               8                 0                 3
Corralien
  • 109,409
  • 8
  • 28
  • 52