Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/309.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用seaborn向带有渐变的条形图添加图例_Python_Seaborn_Legend - Fatal编程技术网

Python 使用seaborn向带有渐变的条形图添加图例

Python 使用seaborn向带有渐变的条形图添加图例,python,seaborn,legend,Python,Seaborn,Legend,我使用seaborn绘制了一个数据框,其中颜色基于列“loan\u status”中的值 数据: 绘图: plt.figure(figsize=(12,4)) g = sns.barplot(x="sub_grade", y= "Count", order= sub_grades, data=df, palette=cm.Blues(df['loan_status'])) 我想为这个图的颜色渐变添加一个图例 我该怎么做?这就是你要找的吗 您可以像这样动态创建颜色栏 g=sns.barplot

我使用seaborn绘制了一个数据框,其中颜色基于列
“loan\u status”
中的值

数据:

绘图:

plt.figure(figsize=(12,4))
g = sns.barplot(x="sub_grade", y= "Count", order= sub_grades, data=df, palette=cm.Blues(df['loan_status']))
我想为这个图的颜色渐变添加一个图例


我该怎么做?

这就是你要找的吗

您可以像这样动态创建颜色栏

g=sns.barplot(x='sub_grade',y='Count',data=df,palete=cm.Blues(df['load_status']))
plt.colorbar(cm.ScalarMappable(cmap=cm.blues))
plt.figure(figsize=(12,4))
g = sns.barplot(x="sub_grade", y= "Count", order= sub_grades, data=df, palette=cm.Blues(df['loan_status']))