seaborn
seaborn copied to clipboard
Alpha values of RGBA color tuples are ignored
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)]
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.
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: https://github.com/mwaskom/seaborn/blob/88479dc3a9c5dee00fa697fda73152add0827fc4/seaborn/relational.py#L937 to allow for setting the alpha value in relation to the hue value. What's your opinion on that?
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.
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.
I would also ask for the same functionality. I am facing this using stripplot
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.
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.
I subscribe also to this feature request.
It is something that is missing in the current seaborn package