How to expand boxes in Seaborn boxplot?

I am trying to create a grouped boxplot using Seaborn ( Link ) 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)

      

enter image description here

If I enlarge or stretch the graphic several times across the width of the screen, I can see these fields, but obviously it is not useful as a standard graphic.

This appears to be a function of my data volume; if i create only the first 500 points (6000) i get visible but small boxes. It could be a high variation feature of my data; according to the boxplot matplotlib documentation,

The default value of [width] is 0.5 or 0.15x (distance between end positions) if less.

Regardless of the reason, there is enough room on the plot itself for the wider boxes if I could just expand them.

Unfortunately the boxplot keyword widths

, which controls the boxplot width, is not a valid keyword factorplot

, and I cannot find a matplotlib function that will change the off-plot bar or box width by the function itself. I can't even find anyone to discuss this; the closest I found is the boxplot line width. Any suggestions?

+3


source to share


1 answer


For future reference, here are the relevant bits of code that make the right figure with the legend: (obviously these are not important things and don't actually get done as they are, but hopefully this shows tricky things)



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)    

      

+1


source







All Articles