Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Orient Pandas users more towards .plot or .hvplot? #1485

Open
maximlt opened this issue Feb 4, 2025 · 0 comments
Open

Orient Pandas users more towards .plot or .hvplot? #1485

maximlt opened this issue Feb 4, 2025 · 0 comments

Comments

@maximlt
Copy link
Member

maximlt commented Feb 4, 2025

TL;DR

Pandas allows declaring a plotting backend different than the default matplotlib one, to which calls to its regular plotting API (e.g. df.plot.line()) will be delegated. hvPlot has supported that for a long time, via pd.options.plotting.backend = 'holoviews/hvplot'. While working on improving the Pandas API guide with @Azaya89, I've started to wonder if hvPlot should steer Pandas users towards that approach or if it should instead steer them towards import hvplot.pandas and the .hvplot namespace.


Pandas added in version 0.25 the possibility to set the plotting backed so that calls to e.g. df.plot.line() are dispatched to the registered backend. It's interesting to note that hvPlot was involved in the discussions about the implementation of this feature pandas-dev/pandas#26747.

How to enable this in hvPlot is currently documented in two places on the website, with pd.options.plotting.backend = 'holoviews':

In #347, hvPlot gained partial (see #1483 why partial only) support for pd.options.plotting.backend = 'hvplot'.

hvPlot is not the only project leveraging this feature:

I did a quick Github search and, while it doesn't return millions of hits, it still seems to be used quite a bit. People even write articles about that (see https://towardsdatascience.com/the-power-of-pandas-plots-backends-6a08d52071d2/ or https://www.nb-data.com/p/easy-interactive-plot-pandas-plotly-backend-6c9772059515).

As a hvPlot user, I'm not sure I've ever used this feature, and if I did I quickly transitioned to directly using the hvplot namespace. There are likely pros and cons for both approaches. I'm wondering if we should orient pandas users (it only applies to this data type) to one of these approaches. Below I tried to see what's the user experience in different environments.


Pandas .plot namespace

Jupyter Lab

Extension:

Loaded on the first .plot call, no visual indication it's loaded (hvPlot doesn't insert a logo).

Warning pre_run_cell IPython hack to reload the extension won't work here if the cell where the extension was loaded is removed or re-executed.

Docstring and signature:

Inherited from Pandas:

Image

VS Code

I have enabled Copilot too. Inherited from Pandas again:

Image

.hvplot namespace

Jupyter Lab

Extension:

Loaded when import hvplot.pandas is executed (not only the first time thanks to the pre_run_cell IPython hack).

Docstring and signature:

Dynamically patched on import (can be improved)

VS Code (python script)

VS Code knows has absolutely no clue about .hvplot :(

Image

VS Code Notebook

TBD

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant