Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

hvplot call inside function does not display in Jupyter Notebook

I am new to hvplot and trying to include a call to .hvplot() inside a function definition, but it's not working. The following code works and displays a figure as expected:

import pandas as pd
import hvplot.pandas

df = pd.DataFrame([1, 5, 3, 4, 2])
df.hvplot()

but if I try something like:

def plot(df):
    df.hvplot()
plot(df)

I get no output. This is in a Jupyter Notebook. What am I missing?

like image 908
Dan Avatar asked Oct 29 '25 21:10

Dan


1 Answers

You need to return the result of your function:

def plot(df):
    return df.hvplot()

plot(df)

Or:

def plot(df):
    my_plot = df.hvplot()
    return my_plot

plot(df)
like image 138
Sander van den Oord Avatar answered Nov 01 '25 11:11

Sander van den Oord