-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Does boxplot support alpha / transparency? #979
Comments
The above is using |
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. |
Fantastic. Thanks @mwaskom ! |
If you're trying to do this in 2022, change 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)) |
Specifically, that is a change in matplotlib 3.5.0. If you are using an older matplotlib in 2022, you should still do it the other way :) |
The following:
Fails with:
I presume boxplots don't support alpha or transparency? Or is there any other way of getting it?
The text was updated successfully, but these errors were encountered: