数据集:
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 :(得分: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()