seaborn - 在pyplot中给出hue时如何更改图例的命名?
问题描述
数据集:
index TARGET NAME_INCOME_TYPE count
0 0 Working 46924
1 0 Commercial associate 21492
2 0 Pensioner 16879
3 0 State servant 6593
4 0 Student 9
5 0 Unemployed 6
6 0 Businessman 4
7 0 Maternity leave 1
8 1 Working 4978
9 1 Commercial associate 1726
10 1 Pensioner 978
11 1 State servant 407
12 1 Unemployed 4
图表代码:
plt.figure(figsize=(20,6))
sns.barplot(x='NAME_INCOME_TYPE',y='percent_rate',hue='TARGET',data=qq,palette='winter',saturation=0.5, hue_order=[0,1])
plt.yticks(size=20)
plt.ylabel(size=20, s = '% rate')
plt.xlabel(size=20, s= 'NAME INCOME TYPE')
plt.xticks(rotation=90,size=20)
plt.legend(loc='upper right')
plt.show()
我已经指定了色调并且它工作正常,但是图例将它作为“0, 1”我想将其更改为“是的,否”。
更改 hue_order 参数不起作用。
更改图例不起作用。
解决方案
好的,显然色调顺序是正确的参数。我只是没有将“0,1”交换为“1,0”。
我编码:
plt.figure(figsize=(20,6))
sns.barplot(x='NAME_INCOME_TYPE',y='percent_rate',hue='TARGET',data=qq,palette='inferno',saturation=0.5,hue_order=['YES', 'NO'])
plt.yticks(size=20)
plt.ylabel(size=20, s = '% rate')
plt.xlabel(size=20, s= 'NAME INCOME TYPE')
plt.xticks(rotation=90,size=20)
plt.title("Income sources of Applicants in terms of loan is repayed or not in %",size=20)
plt.legend(loc='upper right')
plt.show()
推荐阅读
- android - 自定义文本中的android recyclerview分隔符
- python - 对传递给函数的列表进行多处理
- android - 如何在bottomNavigationView android的项目上显示徽章?
- android - 在食品订购应用程序中是否有任何库或小部件用于添加按钮
- jenkins - 工件的版本控制 - CI/CD
- php - 如何使用php显示数组中csv文件的最后一行?
- python - 无法在 python 3.7 上安装 igraph
- php - 如何获取多维数组的名称?
- sql - 在透视连接表中,如果它有值,则仅从其中一个表中返回值
- python - 将所有元素放在具有相同名称的字典形式中