简体   繁体   中英

Seaborn Pairplot Legend Not Showing Colors

I have been learning how to use seaborn and pairplot in python. Everything here seemed to work fine but for some reason the legend will not show the associated colors. I have not been able to find a solution so if anyone has any advice, please let me know.

x = sns.pairplot(stats2,hue='Term',palette='husl',height=15) 在此处输入图像描述

You can first remove the wrong legend, and then add the legend via plt.legend() :

import seaborn as sns; sns.set(style="ticks", color_codes=True)
import matplotlib.pyplot as plt

tips = sns.load_dataset("tips")
g = sns.pairplot(tips[['day', 'tip']], hue='day', palette='husl', height=6)
g._legend.remove()
plt.legend(title='Day')
plt.show()

结果图

PS: To change the ylabel: g.axes[0,0].set_ylabel('distribution', size=15)

Try to add legend explictly

import matplotlib.pyplot as plt

x = sns.pairplot(stats2,hue='Term',palette='husl',height=15) 
x.add_legend()
plt.show()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM