Am I supposed to use `hvplot` only in a jupyter notebook? Where's the basic documentation?

Recently I moved from pandas to polars and it uses hvplot as the visualization tool. The figures are quite fancy (much better than matplotlib) but it appears that some very basic documentation is missing: it didn’t mention anything about the most basic environment to run these stuff. Let’s start with the “Getting Started” section. Following this I was supposing I should just be able to run the code examples freely after pip install hvplot, but it is apparently not the case. My run in an ipython interative shell didn’t plot anything. E.g. these code snippets (from the step-by-step guide here):

import numpy as np
import pandas as pd
np.random.seed(1)

idx = pd.date_range('1/1/2000', periods=1000)
df = pd.DataFrame(np.random.randn(1000, 4), index=idx, columns=list('ABCD')).cumsum()
df.head(2)

import hvplot.pandas  # noqa

first_plot = df.hvplot()
first_plot

only gives me a short poor text output in the ipython console:

Out[8]: 
:NdOverlay   [Variable]
   :Curve   [index]   (value)

Another run in a jupyter notebook created in vscode worked fine (it gives the fancy interactive stuff that I can zoom in and out).

Now my question is: shall we add at least the very basic documentation about how to use the tool? The hvplot official webpage just gives some succinct instruction notes and some short code snippets. A normal user can very likely reads them as “once I install it, I can just run anywhere with a python interpreter”, but that seems not the case at all. If we require it to run in certain places, e.g. a notebook, should we mention it very explicitly? Or am I missing something?

1 Like

Yeah the docs are lacking.

Just for the record, on ipython you need something like this:

import panel as pn

def show(obj):
    pn.serve(obj, threaded=True)

show(first_plot)

which will spin up a panel server (essentially a bokeh server) running on a random port on localhost.

You can close the running servers (in order to e.g. conserve RAM) with:

pn.state.kill_all_servers()
1 Like

The hvplot docs can be improved. But they probably need the input from somebody like you to really improve.

If you are interested try making a github issue describing the things you would like to change. Then make a PR with the proposed changes or ask for help in the issue how to contribute those changes.

Small changes like a few lines in a document is a great first contribution and would be highly appreciated.

Issues · holoviz/hvplot (github.com)

Thanks for the suggestions. I added a new issue and created a PR for this in the hvplot github repo.

fyi I learned from the hvplot repo contributor (reference) that one can just use hvplot.show in a raw python shell to display the plot. Example:

import pandas as pd
import numpy as np
import hvplot
import hvplot.pandas

df = pd.DataFrame(np.random.rand(10, 2))

hvplot.show(df.hvplot())

This seems easier than the import panel approach.

Cool thanks! I was not aware of hvplot.show()

Nevertheless, hvplot.show() defaults to threaded=False which means that most of the time I would still want to define a wrapper.

1 Like

Update: this is resolved by this PR.

1 Like