Seaborn: alpha does not work with violinplot

Created on 2 Jul 2015  路  13Comments  路  Source: mwaskom/seaborn

In seaborn 0.6.0, alpha parameter no longer works with violinplot. Used to work fine with 0.5.1

Example to duplicate:

import seaborn as sns
import matplotlib.pyplot as plt
fig = plt.figure()
sns.set_style("whitegrid")
tips = sns.load_dataset("tips")
ax = sns.violinplot(x=tips["total_bill"], alpha=0.1)
plt.show()

Most helpful comment

you can just do
plt.setp(ax.collections, alpha=.3)

I'd also like to be able to set this from the violin call..

All 13 comments

Yes, that parameter has been removed. Sorry if it didn't make it into the release notes.

In my application, I'm plotting one violinplot over another to see the degree of overlap. Hence, it would be nice if the ability to control the opacity of the plot is restored.

You can always set the alpha on the PolyCollections objects that are attached to the axes object after plotting.

I will try that and let you know! Thanks

That worked. Thanks. Anyway, could it be added to the next sub-release?

I'd like this argument as well - any reason why this was removed?

I also need this alpha parameter, or at least a code snippet how to set the alpha for the PolyCollections object (didn't find anything on the web)

Hello Michael, any chance you could show us a sample of code to change alpha after violinplots have been created using your method (making changes in PolyCollections)?
(p.s. it would be great if alpha is included back again in the arguments)
Thanks

Has anyone been successsful in doing this?
I am not able to figueout how to use PolyCollections with violinplot - and there's still no description in the documentation.

Hi, I am also having trouble finding out how to access the PolyCollections object given the axes object. Would you be able to provide a snippet of example code?

ax.collections

I ended up doing this:

def setAlpha(ax,a):
    for art in ax.get_children():
        if isinstance(art, PolyCollection):
            art.set_alpha(a)

you can just do
plt.setp(ax.collections, alpha=.3)

I'd also like to be able to set this from the violin call..

Was this page helpful?
0 / 5 - 0 ratings

Related issues

amelio-vazquez-reina picture amelio-vazquez-reina  路  3Comments

btyukodi picture btyukodi  路  3Comments

phantom0301 picture phantom0301  路  3Comments

Bercio picture Bercio  路  3Comments

chanshing picture chanshing  路  3Comments