如何加宽 Seaborn boxplot 中的框?

Lan*_*ala 6 graph matplotlib boxplot seaborn

我正在尝试使用 Seaborn ( Reference )制作一个分组的箱线图,并且这些箱子都非常窄——太窄而无法看到分组颜色。

g = seaborn.factorplot("project_code",y="num_mutations",hue="organ",
        data=grouped_donor, kind="box", aspect=3)
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

如果我放大或将图形拉伸到屏幕宽度的几倍,我可以看到这些框,但显然这作为标准图形没有用。

这似乎是我的数据量的函数;如果我只绘制前 500 个点(6000 个),我会得到可见但很小的框。它可能特别是我的数据高方差的函数;根据 matplotlib boxplot 文档,

默认 [宽度] 为 0.5,如果较小,则为 0.15x(极端位置之间的距离)。

不管什么原因,如果我可以加宽它们,图表本身就有足够的空间来容纳更宽的盒子。

不幸的是,widths控制框宽度的 boxplot 关键字不是一个有效的factorplot关键字,我找不到一个 matplotlib 函数来改变绘图函数本身之外的条或框的宽度。我什至找不到任何人讨论这个;我发现最接近的是箱线图线宽。有什么建议?

Lan*_*ala 2

为了将来的参考,这里是用图例制作正确图形的相关代码:(显然这缺少重要的东西并且实际上不会按原样运行,但希望它显示了棘手的部分)

import matplotlib.pylab as pyp
import seaborn as sns

def custom_legend(colors,labels, legend_location = 'upper left', legend_boundary = (1,1)):
    # Create custom legend for colors
    recs = []
    for i in range(0,len(colors)):
        recs.append(mpatches.Rectangle((0,0),1,1,fc=colors[i]))
    pyp.legend(recs,labels,loc=legend_location, bbox_to_anchor=legend_boundary)

# Color boxplots by organ
organ_list = sorted(df_unique(grouped_samples,'type'))
colors = sns.color_palette("Paired", len(organ_list))
color_dict = dict(zip(organ_list, colors))
organ_palette = grouped_samples.drop_duplicates('id')['type'].map(color_dict)

# Plot grouped boxplot
g = sns.factorplot("id","num_mutations",data=grouped_samples, order=id_list, kind="box", size=7, aspect=3, palette=organ_palette)
sns.despine(left=True)
plot_setup_pre()
pyp.yscale('log')
custom_legend(colors,organ_list)    
Run Code Online (Sandbox Code Playgroud)