1

I have a dataframe with the following form:

          0         1         2         3  ...         9        10       11     output
0  2.451775  1.9565675  0.843128 -0.007820  ...  0.74554812  0.090777 -1.90625       a
1 -0.855458 -0.8444604 -0.619685  0.2273399  ... 1.3771857   4.089319 -0.16289       a
2  1.554580  1.9164567  0.643128 -0.0077550  ... 0.7771542   5.090777 -1.90625       b

which was the result of normalizing a numpy´s array and adding the last column named output. I add the last column to be able to use it in a sns.pairplot with the hue=output.

The problem that I have is that my pairplot is displayed with numbers like this: enter image description here

so I what I want is to display instead of numbers 0,1,2,..,n a set of labels, for that reason I have a list of labels like:

labels=["label 1","label 2",...,"label n" ]

that I want to add into my pairplot to have the labels names instead of the index numbers 0, 1,...n-1. I have done the following:

sns.pairplot(df,vars=labels,hue="output")

but I got the following error:

KeyError: 'label 1'

I have tried the option of `reset_index(drop=True), but no results at all. How can I fix this?

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
Little
  • 3,363
  • 10
  • 45
  • 74

1 Answers1

1

I think you can do this by getting the information from the 'matplotlib' axis and setting it.

labels=["label 1","label 2",...,"label n" ]
g = sns.pairplot(df,vars=labels,hue="output")

for ax, lbl in zip(g.axes.flatten(), labels):
    # print(ax, lbl)
    ax.set_ylabel(f'{lbl}')
r-beginners
  • 31,170
  • 3
  • 14
  • 32