[Python] How to disable automatic groupby widget in hvplot?

Discussão em 'Python' iniciado por Stack, Maio 30, 2025.

  1. Stack

    Stack Membro Participativo

    hvplot has a groupby parameter that lets you pick what variables to group the output by. This results in a widget you use to select the data subset you want to plot.

    If groupby is not specified, hvplot often infers what variables you want to group by. For example:

    ds=xr.Dataset({
    'A':(['x','y','z'], np.arange(3*4*5).reshape(3,4,5)),
    'B':(['x','y','z'],2*np.arange(3*4*5).reshape(3,4,5)),
    },
    coords={
    'x':range(3),
    'y':range(4),
    'z':range(5)
    }
    )
    ds.hvplot.scatter('A','B')


    Even though groupby is not specified, hvplot assumes you want groupby=['x','y','z']. So, this creates a widget with sliders for x, y, and z. Since only one point exists for every combination, the resulting scatter plots only have a single point, which isn't very informative!

    Is there a way to force hvplot to plot all values in a single plot? Put another way, is there a way to tell it to not infer a default value for the groupby parameter, and not create a widget? In the above example, this would mean producing a scatter plot of all A and B values in the dataset.

    Continue reading...

Compartilhe esta Página