-
-
Notifications
You must be signed in to change notification settings - Fork 113
Description
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'
:
- https://hvplot.holoviz.org/user_guide/Introduction.html
- https://hvplot.holoviz.org/user_guide/Pandas_API.html
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:
- Plotly documents it properly, see https://plotly.com/python/pandas-backend/
- Pandas_Bokeh (unmaintained at the moment), see https://github.com/PatrikHlobil/Pandas-Bokeh
- Altair had this
altair_pandas
project that was never released https://github.com/altair-viz/altair_pandas? - a few other less-known libraries like https://github.com/lucianosrp/reflex-plot, https://github.com/CDonnerer/shellplot or https://github.com/OpenMS/pyopenms_viz
- (sorry for the ones I missed!)
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:

VS Code
I have enabled Copilot too. Inherited from Pandas again:

.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
:(

VS Code Notebook
TBD