holoviz / hvplot

A high-level plotting API for pandas, dask, xarray, and networkx built on HoloViews
https://hvplot.holoviz.org
BSD 3-Clause "New" or "Revised" License
1.14k stars 109 forks source link

Modify kde alpha channel on plot. #584

Open LinuxIsCool opened 3 years ago

LinuxIsCool commented 3 years ago

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

maximlt commented 2 years ago

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