如何拓宽Seaborn boxplot中的盒子? [英] How to widen boxes in Seaborn boxplot?

查看:195
本文介绍了如何拓宽Seaborn boxplot中的盒子?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Seaborn制作分组boxplot(参考),并且这些框都非常窄 - 太窄而看不到分组颜色。

  g = seaborn.factorplot(project_code,y =num_mutations,hue =organ,
data = grouped_donor,kind =box,aspect = 3)



如果我放大或拉伸几次图形我的屏幕宽度,我可以看到框,但显然这不是一个标准图形有用。

这似乎是我的数据量的函数;如果我只绘制前6000点(6000),我会看到可见的小盒子。它可能具体是我数据高度变化的函数;根据matplotlib boxplot文档,


默认的[width]是0.5或者0.15x(极端位置之间的距离),如果小于。

不管原因如何,如果我可以扩大它们的范围,图形本身就有足够的空间用于更宽的盒子。

p>

不幸的是,控制框宽度的boxplot关键字 widths 不是有效的 factorplot 关键字,并且我找不到一个matplotlib函数,它将改变绘图函数本身之外的条形或框的宽度。我甚至找不到任何人讨论这个问题。我发现最近的是boxplot线宽。任何建议吗?

解决方案

为了将来的参考,下面是代码的相关部分,是缺少重要的东西,并不会实际运行,但希望它显示棘手的部分)

  import matplotlib.pylab作为pyp 
将seaborn导入为sns

def custom_legend(颜色,标签,legend_location ='左上角',legend_boundary =(1,1)):
#创建自定义图例(0,len(colors)):
recs.append(mpatches.Rectangle((0,0),1,1,fc = (颜色[i]))
pyp.legend(recs,labels,loc = legend_location,bbox_to_anchor = legend_boundary)

颜色boxlot by organ
organ_list = sorted(df_unique(grouped_samples ,'type'))
colors = sns.color_palette(Paired,len(organ_list))
color_dict = dict(zip(organ_list,colours))
organ_palette = grouped_samples.drop_duplicates( 'ID )['type']。map(color_dict)

#绘制分组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)


I'm trying to make a grouped boxplot using Seaborn (Reference), and the boxes are all incredibly narrow -- too narrow to see the grouping colors.

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

If I zoom in, or stretch the graphic several times the width of my screen, I can see the boxes, but obviously this isn't useful as a standard graphic.

This appears to be a function of my amount of data; if I plot only the first 500 points (of 6000), I get visible-but-small boxes. It might specifically be a function of the high variance of my data; according to the matplotlib boxplot documentation,

The default [width] is 0.5, or 0.15x(distance between extreme positions) if that is smaller.

Regardless of the reason, there's plenty of room on the graph itself for wider boxes, if I could just widen them.

Unfortunately, the boxplot keyword widths which controls the box width isn't a valid factorplot keyword, and I can't find a matplotlib function that'll change the width of a bar or box outside of the plotting function itself. I can't even find anyone discussing this; the closest I found was boxplot line width. Any suggestions?

解决方案

For future reference, here are the relevant bits of code that make the correct figure with legend: (obviously this is missing important things and won't actually run as-is, but hopefully it shows the tricky parts)

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)    

这篇关于如何拓宽Seaborn boxplot中的盒子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆