我正在尝试设置使用barplot
创建的seaborn
的边缘颜色。问题似乎是当我使用hue参数时。
edgecolor参数不是为每个单独的条具有单独的颜色,而是将颜色应用于整个色调/组。
通过这个简单的例子重现问题。
tips = sns.load_dataset("tips")
t_df = tips.groupby(['day','sex'])['tip'].mean().reset_index()
因此t_df将是,
clrs = ["#348ABD", "#A60628"]
t_ax = sns.barplot(x='day',y='tip',hue='sex',data=t_df,alpha=0.75,palette= sns.color_palette(clrs),edgecolor=clrs)
plt.setp(t_ax.patches, linewidth=3) # This is just to visualize the issue.
这给出了输出,
我想要的是蓝色条应该是蓝色边缘颜色和红色相同。这需要什么代码更改?
答案 0 :(得分:2)
这有些蠢,但它完成了工作:
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
@ mwaskom的建议显然更清晰。为了完整性:
import matplotlib.patches
# grab everything that is on the axis
children = t_ax.get_children()
# filter for rectangles
for child in children:
if isinstance(child, matplotlib.patches.Rectangle):
# match edgecolors to facecolors
clr = child.get_facecolor()
child.set_edgecolor(clr)