-
-
Notifications
You must be signed in to change notification settings - Fork 105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A keyword argument to show individual points when zoomed, else datashade #597
Comments
The discussion on Discourse started with this first example that creates an overlay of points and its datashaded version, the points being not displayed over a threshold taken as the number of points contained in the view port (5000 in the example). import numpy as np
from holoviews.operation.datashader import datashade
import holoviews as hv
hv.extension('bokeh')
points = hv.Points(np.random.multivariate_normal((0,0), [[0.1, 0.1], [0.1, 1.0]], (500000,)))
def filter_points(points, x_range, y_range):
if x_range is None or y_range is None:
return points
return points[x_range, y_range]
def hover_points(points, threshold=5000):
if len(points) > threshold:
return points.iloc[:0]
return points
range_stream = hv.streams.RangeXY(source=points)
streams=[range_stream]
filtered = points.apply(filter_points, streams=streams)
shaded = datashade(filtered, width=400, height=400, streams=streams)
hover = filtered.apply(hover_points)
dynamic_hover = (shaded * hover).opts(
hv.opts.Points(tools=['hover'], alpha=0.1, hover_alpha=0.2, size=10)) Then Philipp showed that there's the import holoviews as hv
from holoviews.operation.datashader import rasterize
from holoviews.operation import apply_when
points = hv.Points(np.random.randn(100000, 2)).opts(tools=['hover'], alpha=0.1, hover_alpha=0.2, size=10)
# The operation can be customized by creating an instance of it.
my_custom_rasterize = rasterize.instance(x_sampling=0.25, y_sampling=0.25, aggregator="max")
apply_when(points, operation=my_custom_rasterize, predicate=lambda x: len(x) > 5000) At the time @jbednar said:
When I started to work on hvPlot I thought that hvPlot users should pretty much never have to interact with HoloViews directly. I've changed my mind on this topic, I believe there are specific parts of HoloViews that are simple enough to be exposed to hvPlot users, when they need that extra power or more flexibility, and using the operations is I believe one of these areas. In this particular case I would argue that we first need to document the
Imo I think that only after this is completed we could think about adding to hvPlot's API the possibility to directly get this behavior. |
I support having those docs! Note that there are hvplot-specific aspects to |
Related to holoviz/holoviews#5512 |
Implemented in #1103 |
ds.hvplot('lon', 'lat', zoom_datashade=True)
I wonder if it'd be possible to create an keyword argument like zoom_datashade=True that calls this
https://discourse.holoviz.org/t/show-individual-points-when-zoomed-else-rasterize/2204
The text was updated successfully, but these errors were encountered: