How to select / extract a subplot from the layout

Hi,
I have a layout and I would like to use the use custom columns in my data to query the subplot. is there an easy way to that ? Here my code

import holoviews as hv
import pandas as pd
import numpy as np
hv.extension('bokeh')

# Create a DataFrame with standard data + extra metadata
df = pd.DataFrame({
    'x': [1, 2, 3], 'y': [2, 4, 6],
})
df['coord'] = 1
df2 = pd.DataFrame({
    'x': [1, 2, 3], 'y': [2, 4, 6],
})
df2['x'] += 1
df2['y'] += 1
df2['coord'] = 3
points = hv.Points(df, kdims=['x', 'y'])
points2 = hv.Points(df2, kdims=['x', 'y'])
plot = points + points2
plot.select(coord=1)

Full plot layout is


using select
if I use plot.select(coord=1) I obtain the still the full layout with one of the 2 plot empty. I would like to extract only the subplot instead

I know I can use the dotted syntax to access to elements of a nested layout, but in this way the only deegrees of freedom are ‘label’ and ‘group’. Instead I would to like to have custom metadata to use to query the subplots

I don’t fully understand what you mean by

if I use plot.select(coord=1) I obtain the still the full layout with one of the 2 plot empty. I would like to extract only the subplot instead

Can you clarify and show me what the end goal is? It’s ambiguous what coord=1 means here.

Sure, thanks for the answer and the patience !
The end goal is to extract only the subplot containing data with coord=1. So, in this case only the first subplot in the layout should be extracted (the hv.Points created with df not df2.
So the goal is to create layouts containing data columns (the coord column in this example) acting as metadata, so that you can extract / select subplots containing that metadata from the full layout.

More context

I’m trying to achieve this because I’d like to iteratively update the subplots with new data on demand, but only for few of them. For example, I could add a new set of points only for the subplots containing coord=1 as metadata, so I need to select them in a robust way. I think that ‘label’ and ‘group’ doesn’t fit in this scenario because, depending on the scenario, I could have an arbitrary number of metadata columns acting as and id to identify the particular data in the subplots. With this way of selecting the subplots I hope it will be easier updating them with new data even if I have nested structure.
Important: I am new to this framework, so suggestions to how to achieve this goal are welcome !

Coming back to the question
Here instead, with plot.select(coord=1) I obtain still the full layout (both subplots) with one subplot empty (the one with coord=3 is empty) Instead I would like to obtain only this


that is: the same result as if I used the dotted notation to access to elements in the layout.

Can you subset like this?

import holoviews as hv

hv.extension("bokeh")

l = hv.Curve([0, 1, 2]) + hv.Scatter([0, 1, 2])
l[0]

Alternatively loop through?

import holoviews as hv

hv.extension("bokeh")

l = hv.Curve([0, 1, 2], label="C") + hv.Scatter([0, 1, 2], label="S")
for el in l:
    if el.label == "C":
        el.opts(color="red")
        break
el

Hi thanks for the answer !
At the end I think I found the solution: using hv.NdLayout to create mult dim keys and then using .select to get the subplots !
Here the example refactored using dim1 and dim2 just to have an example with 2 kdims.

then you can extract only the first subplot using select.

ly.select(dim1='a')

1 Like