Skip to content

Conversation

@philippjfr
Copy link
Member

@philippjfr philippjfr commented Mar 21, 2022

Selects one of multiple datashaded curves by drawing a vertical line at the x-position and identifying all points of intersection of that line on the rasterized plot. The intersection closest to the specified y-coordinate is picked and the data of all rasterized curves is searched for proximity to that coordinate.

Here's a demo with 10 curves with 100k points each:

xs = pd.date_range('2010-01-01', '2022-01-01', freq='1h')
ts = hv.NdOverlay({i: hv.Curve((xs, np.random.randn(len(xs)).cumsum())) for i in range(10)})
raster = rasterize(ts)

overlay = inspect_curve(raster).opts(tools=['hover'])
overlay.streams[0].source = raster
(raster * overlay).opts(width=800)

inspect_curve

Copy link
Member

@jbednar jbednar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very cool, thanks! It's important to document precisely what the implications, limitations, and costs of this approach are, especially compared to other possible implementations. My guesses:

  • It appears to assume that the curve is (nearly) a function, i.e. that there is at most one y value for a given x value (or that if there are multiple, they are connected vertically, not fully disjoint?). If so, that's fine and a useful assumption, but should be clearly documented, and other inspect functions could relax that assumption if needed.
  • From what I can see, if a particular curve crosses close to the clicked location but does not happen to have a vertex near the location, then my understanding is that it won't be selected, either because it doesn't fit the tolerance or because another curve not as close to the click but with a vertex that's within tolerance gets selected. That's a limitation that should be documented, but may be ok; we can tell people to click near a vertex in such a situation.
  • I wonder if there is a practical alternative that interpolates each curve at the available x values, computing the y value explicitly, and then can do a cheap lookup of the y value when it gets a click. That would optimize clicking or hovering performance, but may incur a cost in memory and CPU whenever the viewport changes.

Not sure what other alternatives there are.

@bt-
Copy link

bt- commented Sep 17, 2025

Was this implemented? I would love to have access to the functionality shown in the demo!

Looks like something similar was implemented. I landed here from a link in the Datashader docs, linked text is inspect_curve in the Dynamic Plots section.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants