How to transform a column before plotting with hvplot?

Hello,

I often need to plot slightly different versions of my data depending on who’s requesting data from me. Is there a way to plot using hvplot such that I don’t have to keep saving out additional columns in dataframes?

E.g.,
Original Plot: probability as a decimal

demo_df = pd.DataFrame({‘value’:np.random.randn(50),‘probability’:np.random.rand(50)})
demo_df.hvplot.scatter(x=‘value’,y=‘probability’)

Desired: plotting the ‘probability’ as a percentage instead.
I tried…

percent = hv.dim(‘probability’)*100
demo_df.hvplot.scatter(x=‘value’,y=percent)

…but that didn’t work. Is there another simple/recommended way?

1 Like

I think that should be supported, would you mind filing an issue with hvPlot to support this? For now the only way of doing this is to modify the DataFrame or assign a new column.

I did that… here:

My first issue/feature request.

Thank you! :slightly_smiling_face:

1 Like

Yay, much appreciated!

@philippjfr @jbednar Had another follow-up use case that came up… how do I dim transform using multiple columns before plotting? The example, which throws a DataError is trying to take a ratio of two columns p1/p2 (on y-axis) before plotting against the expected value (on the x-axis).

demo_df = pd.DataFrame({'value':np.random.randn(50),'p1':np.random.rand(50),'p2':np.random.rand(50)})
ratio = hv.dim('p1')/hv.dim('p2')
demo_df.hvplot.scatter(x='value',y='ratio').apply.transform(ratio=ratio)