Skip to content

Should selector honor vdims? #6594

@maximlt

Description

@maximlt

selector allows displaying additional values in a hover tooltip. As far as I understand, the additional values are extracted from the variables present in the underlying data object, separately from the declared/inferred vdims. I'm opening this issue to discuss whether the variables included in the tooltip should honor vdims.

import datashader as ds
import numpy as np
import pandas as pd

import holoviews as hv
from holoviews.operation.datashader import datashade, dynspread, rasterize

hv.extension("bokeh")

# Set default hover tools on various plot types
hv.opts.defaults(hv.opts.RGB(tools=["hover"]), hv.opts.Image(tools=["hover"]))


def create_synthetic_dataset(x, y, s, val, cat):
    seed = np.random.default_rng(1)
    num = 10_000
    return pd.DataFrame(
        {"x": seed.normal(x, s, num), "y": seed.normal(y, s, num), "s": s, "val": val, "cat": cat}
    )


df = pd.concat(
    {
        cat: create_synthetic_dataset(x, y, s, val, cat)
        for x, y, s, val, cat in [
            (2, 2, 0.03, 0, "d1"),
            (2, -2, 0.10, 1, "d2"),
            (-2, -2, 0.50, 2, "d3"),
            (-2, 2, 1.00, 3, "d4"),
            (0, 0, 3.00, 4, "d5"),
        ]
    },
    ignore_index=True,
)

By default and for a non-rasterized element:

  • holoviews infers the vdims
  • all the vdims are included in the tooltip
points = hv.Points(df.sample(n=1000)).opts(tools=['hover'])
print(points)
points
Image

Setting explicitly the list of vdims affects the variables displayed in the tooltip:

points = hv.Points(df.sample(n=1000), kdims=['x', 'y'], vdims=['s', 'cat']).opts(tools=['hover'])
print(points)
points
Image

Now we'll look at how vdims interact with aggregator and selector. We'll start by not declaring explicitly the dimensions. The output looks similar to what we got with the non-rasterized plot, all the remaining variables are included in the tooltip.

points = hv.Points(df)
rasterize(points, aggregator=ds.mean('s'), selector=ds.min('val'))
Image

Let's declare a Points element with only 's' as a vdim.

points = hv.Points(df, kdims=['x', 'y'], vdims=['s'])

An error is raised when attempting the use an aggregator on 'val', a variable not included in the dimensions

rasterize(points, aggregator=ds.mean('val'))
ValueError: Aggregation column 'val' not found on ':Points   [x,y]   (s)' element. Ensure the aggregator references an existing dimension.

No error is raised when setting selector to a variable that is not part of any of the element dimensions.

rasterize(points, aggregator=ds.mean('s'), selector=ds.min('val'))
Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    TRIAGENeeds triaging

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions