Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

question from:https://stackoverflow.com/questions/65907096/hvplot-call-inside-function-does-not-display-in-jupyter-notebook

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
324 views
Welcome To Ask or Share your Answers For Others

1 Answer

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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...