hvplot icon indicating copy to clipboard operation
hvplot copied to clipboard

Modify kde alpha channel on plot.

Open LinuxIsCool opened this issue 4 years ago • 1 comments

I don't think it's possible to modify the alpha channel on kde plots. The alpha parameter only modifies the borders. It would be nice to be able to modify the alpha of the distributions.

Example code:

import numpy as np
import pandas as pd
import hvplot.pandas

size=400

y_target = np.random.normal(0,1.5,size)
y_predictions = np.random.normal(1,1,size)
performance = pd.DataFrame(list(zip(y_target,y_predictions)),columns=['y_target','y_predictions'])

performance.hvplot.kde(alpha=1) + performance.hvplot.kde(alpha=0.1)

image

LinuxIsCool avatar Apr 06 '21 02:04 LinuxIsCool

For now (hvPlot 0.8.0) the workaround is to use fill_alpha instead of alpha, and this for the Bokeh backend.

performance.hvplot.kde(fill_alpha=1) + performance.hvplot.kde(fill_alpha=0.1)

image

The issue comes down to the fact that HoloViews sets the default value of fill_alpha for Distribution elements (the element used by df.hvplot.kde): https://github.com/holoviz/holoviews/blob/39863f54b9c61f8608b542577a739f53ae0b8b9d/holoviews/plotting/bokeh/init.py#L284-L287

alpha is a special parameter for Bokeh:

An alias to set all alpha keyword arguments at once. (default: None) Alpha values must be between 0 (fully transparent) and 1 (fully opaque). Any explicitly set values for line_alpha, etc. will override this setting.

So when any other x_alpha parameter is set, like fill_alpha, alpha then just applies to the x_alpha parameters.

@jlstevens what would you expect at the HoloViews level? Should the plot below have fill_alpha=1?

import numpy as np
import holoviews as hv
hv.extension('bokeh')

normal = np.random.randn(1000)
hv.Distribution(normal).opts(alpha=1)

image

maximlt avatar Oct 18 '22 08:10 maximlt