Repository: holoviz/holoviews

Issue:
Datashader min_alpha not in Holoviews
Hi, I am new both at Holoviews and Datashader. But I tried to get the same plot that I get using datashader using Holoviews but it is being impossible because the datashade function does not have this min_alpha parameter that is present if I only use datashader function tf.shade.

It is important, since as I zoom in I get only a few bins really intense which mask almost the rest of the image.

Thank you

Code in datashader (part of if):
background = "black"
export = partial(export_image, export_path="export", background=background)
cm = partial(colormap_select, reverse=(background=="black"))

def create_image(x_range, y_range, w=plot_width, h=plot_height):
    cvs = ds.Canvas(plot_width=w, plot_height=h, x_range=x_range, y_range=y_range)
    agg = cvs.points(data, 'X_coordinate', 'Y_coordinate', ds.count_cat("Gene"))
    img = tf.shade(agg, how = "eq_hist", min_alpha = 255)
    spread = tf.dynspread(img, threshold = 0.1, max_px = 1, how="over")
    return spread

p = base_plot(background_fill_color=background)
export(create_image(*data_smFISH_coords),"5_smFISH")
InteractiveImage(p, create_image)

Code using Holoviews ():
import numpy as np
import holoviews as hv
import datashader as ds
from holoviews.operation.datashader import aggregate, datashade, dynspread, shade

hv.notebook_extension('bokeh')
dynspread.max_px=1
dynspread.threshold=0.5
shade.cmap="#30a2da" # to match HV Bokeh default
data_smFISH = data
data_smFISH["Gene"] = data_smFISH["Gene"].astype("str")
dic_data = {i : hv.Points(data_smFISH[data_smFISH["Gene"].apply(lambda x: x == i)]
      [["X_coordinate", "Y_coordinate"]]) for i in data["Gene"].unique()}
Nd = hv.NdOverlay(dic_data, kdims=["Gene"])
agg = datashade(Nd, aggregator=ds.count_cat('Gene'))
dynspread(agg, how = "over")







Discussion:
Thanks for reporting this.

We should expose as much functionality from datashader as we can so I'm assigning this issue to the next milestone. I don't expect it will take too much effort to support. @philippjfr Can you confirm that there is no easy way to set ``min_alpha`` currently?
Yes, I have read through the datashader.py script and at some point it transforms the RGBA to RGB (as I understood), therefore, there isn't any alpha or min_alpha parameter to optimize. Which practically means that the plot is the same as the equivalent to using datashader with min_alpha = 0.

I have also tried different things, but nothing solved the problem.

Thank you for your time
Right; this is an omission from ``holoviews.operation.datashader.shade()``, which was probably written before we added ``min_alpha`` to datashader.  Should be trivial; I'll make a PR.

Resolving patch:
diff --git a/holoviews/operation/datashader.py b/holoviews/operation/datashader.py
--- a/holoviews/operation/datashader.py
+++ b/holoviews/operation/datashader.py
@@ -530,6 +530,12 @@ class shade(Operation):
         Disable when you do not want the resulting plot to be interactive,
         e.g. when trying to display an interactive plot a second time.""")
 
+    min_alpha = param.Number(default=40, doc="""
+        The minimum alpha value to use for non-empty pixels when doing
+        colormapping, in [0, 255].  Use a higher value to avoid
+        undersaturation, i.e. poorly visible low-value datapoints, at
+        the expense of the overall dynamic range..""")
+
     @classmethod
     def concatenate(cls, overlay):
         """
@@ -577,7 +583,7 @@ def _process(self, element, key=None):
 
         # Compute shading options depending on whether
         # it is a categorical or regular aggregate
-        shade_opts = dict(how=self.p.normalization)
+        shade_opts = dict(how=self.p.normalization, min_alpha=self.p.min_alpha)
         if element.ndims > 2:
             kdims = element.kdims[1:]
             categories = array.shape[-1]


Test patch: