question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Does boxplot support alpha / transparency?

See original GitHub issue

The following:

sns.boxplot(data, x='foo', y='bar', alpha=0.3)

Fails with:

TypeError: boxplot() got an unexpected keyword argument 'alpha'

I presume boxplots don’t support alpha or transparency? Or is there any other way of getting it?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:4
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

59reactions
mwaskomcommented, Sep 4, 2022

It’s not supported through the seaborn API, but it is through kwargs that are passed down to matplotlib:

ax = sns.boxplot(x='day', y='tip', data=tips, boxprops=dict(alpha=.3))

But this also sets the alpha on the edges of the boxes, which I find aesthetically displeasing. A more roundabout way to grab the patch artists after plotting and then to just change the alpha of the box fills:

ax = sns.boxplot(x='day', y='tip', data=tips)
for patch in ax.artists:
    fc = patch.get_facecolor()
    patch.set_facecolor(mpl.colors.to_rgba(fc, 0.3))

there may be a more direct but less obvious way to do that, usually is in matplotlib.

10reactions
vinisalazarcommented, Jun 2, 2022

If you’re trying to do this in 2022, change ax.artists for ax.patches, like so:

ax = sns.boxplot(x='day', y='tip', data=tips)
for patch in ax.patches:
    r, g, b, a = patch.get_facecolor()
    patch.set_facecolor((r, g, b, .3))
Read more comments on GitHub >

github_iconTop Results From Across the Web

boxplot_alpha: Alpha Boxplot - Microbiome Analytics - Rdrr.io
Controls the transparency of plots elements. If using boxplot and and points together how to deal with outliers. See ggplot2 outlier. fill ...
Read more >
Matplotlib: how to have a transparent box plot face while a non ...
set_alpha changes both face color and edge color, to avoid that, you may want to consider passing RGBA values directly to face color:...
Read more >
Overlapping boxplots with transparency - Bioconductor Forum
Hi Fong, > Hi, > > I am pretty stumped on how I can approach this problem. Basically, I have > two groups...
Read more >
Control colors in a Seaborn boxplot - Python Graph Gallery
I personally think that charts look better with transparency. I find out how to do it using mwaskom's Github post. If you want...
Read more >
Add transparency to objects in axes - MATLAB alpha
alpha value sets the face transparency for objects in the current axes that support transparency. Specify value as 'clear' or 'opaque' , or...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found