Repository: holoviz/holoviews

Issue:
Decimate not updating/resampling
I experienced a problem using the holoviews decimate function: When zooming into a large set of datapoints, the resampling of the decimated points is only done, when the total number points in the displayed area is below the decimate sample threshold. This means, on a distinct zoom level, you might end up with single points of data (see Figure 1) and zooming in another step resamples the datapoints and you end up with as many data points as specified in the threshold (see Figure 2) which is very confusing especially for a user which might not know that the plot uses sampled data points.
I would expect that the decimate function resamples the data on each zoom level such that the number of points in the displayed area of each zoom level does not exceed the threshold but is also not significantly below it. Is this the intended functionality? Or are there any options which need to be additionally specified?

Please find a minimal working example for testing purposes below: 

    import numpy as np
    import pandas as pd

    numPoints = 1000000; 
    xNormal = np.random.normal(0,10,numPoints)
    yNormal = np.random.normal(0,5,numPoints)
    d = {'x': xNormal, 'y': yNormal}
    normal_df = pd.DataFrame(data=d)


    import holoviews as hv
    from holoviews.operation import decimate
    hv.extension('bokeh')

    source_df = normal_df
    visualization_data = decimate(hv.Points(source_df, ['x', 'y']),max_samples=1000)
    visualization_data.opts(
                width    = 800,
                height   = 800, 
                size     = 8
                )


![Figure 1: Only few data points are displayed.](https://user-images.githubusercontent.com/47863197/62117899-14db7300-b2bd-11e9-970a-4617119f16b3.PNG)
Figure 1: Only few data points are displayed.
![Figure 2: The data points were resampled on a deeper zoom level (see the limit of axes in comparison to Figure 1).](https://user-images.githubusercontent.com/47863197/62117901-15740980-b2bd-11e9-939d-e6e5247a8651.PNG)
Figure 2: The data points were resampled on a deeper zoom level (see the limit of axes in comparison to Figure 1).




Discussion:
>I would expect that the decimate function resamples the data on each zoom level such that the number of points in the displayed area of each zoom level does not exceed the threshold but is also not significantly below it. Is this the intended functionality?

No this is definitely not expected, the number of points should always be ``min(max_samples, n_datapoints_in_viewport)``.
It's a very simple bug it's selecting a random sample on the original and not the sliced data.

Resolving patch:
diff --git a/holoviews/operation/element.py b/holoviews/operation/element.py
--- a/holoviews/operation/element.py
+++ b/holoviews/operation/element.py
@@ -709,7 +709,7 @@ def _process_layer(self, element, key=None):
 
         if len(sliced) > self.p.max_samples:
             prng = np.random.RandomState(self.p.random_seed)
-            return element.iloc[prng.choice(len(sliced), self.p.max_samples, False)]
+            return sliced.iloc[prng.choice(len(sliced), self.p.max_samples, False)]
         return sliced
 
     def _process(self, element, key=None):


Test patch: