python - Seaborn pairplot: how to change legend label text -
i'm making simple pairplot seaborn in python shows different levels of categorical variable color of plot elements across variables in pandas dataframe. although plot comes out want it, categorical variable binary, makes legend quite meaningless audience not familiar data (categories naturally labeled 0 & 1).
an example of code:
g = sns.pairplot(df, hue='categorical_var', palette='set3')
is there way change legend label text pairplot? or should use pairgrid, , if how approach this?
since don't provide full example of code, nor mock data, use own codes answer.
first solution
the easiest must keep binary labels analysis , create column proper names plotting. here sample code of mine, should grab idea:
def transconum(morph): if (morph == 's'): return 1.0 else: return 0.0 compactgroups['morphnum'] = compactgroups['morphgal'].apply(transconum)
second solution
another way overwrite labels on flight. here sample code of mine works perfectly:
grid = sns.jointplot(x="morphnum", y="props", data=compactgroups, kind="reg") grid.set_axis_labels("central type", "spiral proportion among satellites") grid.ax_joint.set_xticks([0, 1, 1]) plt.xticks(range(2), ('$red$', '$s$'))
Comments
Post a Comment