python - 在 seaborn 计数图中标记每种颜色
问题描述
我正在尝试绘制一个具有很长 x 值的 seaborn 计数图,这些值实际上是句子。因此,与其将它们插入 xticks 下,我认为使用 countplot 的色调参数并将标签放在图例中可能会更好。但这会产生彼此相距很远的极细条(参见下面的示例),当我希望这些条成为我没有为色调参数分配任何东西时的样子。我该如何解决?
例子:
df0 = pd.DataFrame({'col':['This is a very long string. So yeah, there you have it, a long, long string.',
'What, you egg? said William Shakespeare.',
'OK, this is now getting out of hand.']})
seaborn.countplot(df0['col'], hue=df0['col'])
plt.legend(loc='upper left', bbox_to_anchor=(1, 1))
此代码产生
我想要的图表:
解决方案
根据: http ://seaborn.pydata.org/generated/seaborn.countplot.html#seaborn.countplot
您需要添加dodge=False
到您的通话中countplot
闪避:布尔,可选
使用色调嵌套时,是否应沿分类轴移动元素。
seaborn.countplot('col', hue='col', dodge=False, data=df0)
推荐阅读
- python - 提高性能处理 Pandas 数据帧 (isin)
- sql-update - 在普遍 PSQL 更新语句期间忽略锁定的记录
- laravel - htmlspecialchars() 期望参数 1 是字符串,给定 Laravel 5.6 的数组
- ruby - RSpec 中的 DRY 双倍
- mysql - 如何对多个表中存在的相同列求和并将结果显示为一个
- linux - 如何在 Linux 3.4 内核中禁用 cpu 内核?
- angularjs - 如何在 angularjs-dropdown-multiselect 指令中使用 ng-blur 函数
- angular - 发射器功能没有得到处理
- java - Java - 如何使用 PrintStream/OutputStream 打印到命令行
- asp.net - 没有继承的 EF 6 中恼人的鉴别器列