Skip to content
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

Alpha values of RGBA color tuples are ignored #1966

Open
Huii opened this issue Feb 19, 2020 · 8 comments
Open

Alpha values of RGBA color tuples are ignored #1966

Huii opened this issue Feb 19, 2020 · 8 comments

Comments

@Huii
Copy link

Huii commented Feb 19, 2020

Thank you very much for providing this awesome library. Unfortunately, I found a bug concerning the handling of the transparency values in RGBA colour tuples. The alpha value is simply being ignored, as

print(sns.color_palette([(1,1,1,0)]))
only results in the following output:

[(1.0, 1.0, 1.0)]

@mwaskom
Copy link
Owner

mwaskom commented Feb 24, 2020

It is not a bug, in the sense that the behavior matches what is documented:

Returns
    palette: list of RGB tuples

One might wish that RGBA input yields RGBA output, which might be reasonable. But there are many matplotlib functions where the alpha channel of the color input is ignored and the opacity is controlled globally by a separate parameter. So in most cases, this would not work as well as expected.

@Huii
Copy link
Author

Huii commented Feb 25, 2020

Thank you very much for your reply. I would still prefer to be able to set the alpha value myself. Otherwise, I wouldn't, for example, be able to create a scatterplot with varying degrees of transparency for different categories.

Related to that, it would maybe be a good idea to change the following line of code:

kws["alpha"] = 1 if self.alpha == "auto" else self.alpha
to allow for setting the alpha value in relation to the hue value. What's your opinion on that?

@ImportanceOfBeingErnest

But there are many matplotlib functions where the alpha channel of the color input is ignored and the opacity is controlled globally by a separate parameter. So in most cases, this would not work as well as expected.

In matplotlib the alpha parameter takes precendence over individual color's alpha channel; however, if you don't specify a global alpha, it will obey to full RGBA throughout. If there is a case where it doesn't, it should be reported as bug.

@mwaskom
Copy link
Owner

mwaskom commented Mar 17, 2020

Yes I misspoke; I meant there are seaborn functions that work that way.

Part of the challenge is that some seaborn functions (e.g. lineplot with an error band, kdeplot with shaded density) use the color for multiple elements but explicitly set different alpha channels. In other functions (e.g. boxplot or violinplot), the color set by the palette applies only to one matplotlib element, but you might want more global control over the opacity of the whole plot.

So, it's tricky.

@aliechoes
Copy link

I would also ask for the same functionality. I am facing this using stripplot

@pollackscience
Copy link

Would also be useful for barplot if you want to overlay two plots and use alpha to highlight or annotate certain sections of the original plot. Non-standard usage, I know, but still would be good for me.

@NickFabry
Copy link

FWIW, I'd like this as well; my use case is for stripplot, where there are too many data points to effectively use swarmplot. Using stripplot with a low alpha allows a 'cloud' effect to give some idea of density to non-stats people for whom a violin plot would be too much. But, there is another category of points that are unusual and rare, so I want them to be opaque. Unfortunately, I discovered (after much frustration) that the alpha settings in the colors provided to the palette argument are ignored.

Even documenting this behavior would be useful, as one would not keep experimenting, trying to figure out what they were doing wrong.

@marquez85
Copy link

I subscribe also to this feature request.

It is something that is missing in the current seaborn package

Repository owner locked and limited conversation to collaborators Sep 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants