Changing the HexTiles size according to a column value

I am working on a telecommunication project for which I want to create a HexTiles map. I managed to change the size of each HexTile according to the count of values that fall inside the HexTile. However, for this project, I want to change the size according to a column value in the dataset.
I was able to achieve this on ‘matplotlib’ using the ‘hexbin’ function like this:

df_operator.plot.hexbin(x="LocationLongitude",
                        y="LocationLatitude", 
                        C="TrafficVolume", 
                        reduce_C_function=np.sum,
                        cmap="viridis",
                        figsize=(15,15))

Which gives this static plot:

It’s exactly what I want, but when I try to integrate this into ‘Panel’ to create a dashboard, it doesn’t change dynamically.

I used the following function to create the HexTiles in HoloViews, but I can’t find a way to change the size according to a column value.

COLORS = {"Operator A": cc.kr, "Operator B": cc.kg, "Operator C": cc.kb}

def operator_map(operator_name):
    df_operator = df[df["RadioOperatorName"] == operator_name].copy()
    operator_tiles =  hv.element.HexTiles(df_operator, kdims=["LocationLongitude", "LocationLatitude"])
    operator_tiles.opts(cmap=COLORS[operator_name], 
                        alpha=0.8, 
                        cnorm="log", 
                        tools=["hover"], 
                        width=1000, 
                        height=700, 
                        scale=(hv.dim('Count').norm()*0.5)+0.5)
    return operator_tiles

Is this achievable in Holoviews? What should I use?

It should be possible. You can use pn.bind and a pn.widgets.Select. If you want a more concrete answer, I need to see a minimal, reproducible example (MRE)?

In general, a complete script that can be copied/pasted and immediately run, as-is, with no modifications. This is much more useful than snippets.

Thanks for your reply @Hoxbro.
I tried using a widget and bind, and it works, only with Holoviews maps, but the issue is that the size of the tile isn’t in accordance with the ‘TrafficVolume’ but rather with the number of data points inside the ‘HexTile’.
My issue isn’t with binding the map with the widgets, but with controlling the size of the HexTiles. The map produced using Holoviews is different from the one produced by Matplotlib. This is the one produced by Holoviews:

I have attached a test.py script and the database I’m using.
test.py (2.0 KB)
Downlink_traffic.csv (7.7 MB)

I managed to solve the issue using the following code:

COLORS = {"Operator A": cc.kr, "Operator B": cc.kg, "Operator C": cc.kb}
AGGS = {"Average": np.mean, "Minimum": np.min, "Maximum": np.max, "90th Percentile":pd.DataFrame.quantile}
PLOT_WIDTH = 900
PLOT_HEIGHT= 700
def traffic_plot(operator_name):
    """Plots a hexbin for each operator where the size of each hex depends on the counts of values that falls inside this hex"""
    df_operator = df[df["RadioOperatorName"] == operator_name]
    if (len(df_operator) == 0 ):
        return esri
    operator_tiles =  hv.element.HexTiles(df_operator, kdims=["LocationLongitude", "LocationLatitude"], vdims=["TrafficVolume"])
    operator_tiles.opts(cmap=COLORS[operator_name], alpha=0.8, cnorm="linear", tools=["hover"], width=PLOT_WIDTH, height=PLOT_HEIGHT, scale=(hv.dim('TrafficVolume').norm()*0.5)+0.5)
    return (esri * operator_tiles).opts(hv.opts.HexTiles(aggregator=np.sum))

The trick is to add the column as a ‘vdim’ and then set the aggregator to the sum. The biggest tile will also have the highest value in the colormap, as you see below:

1 Like