holoviz / hvplot

A high-level plotting API for pandas, dask, xarray, and networkx built on HoloViews
https://hvplot.holoviz.org
BSD 3-Clause "New" or "Revised" License
1.02k stars 99 forks source link

hvplot and holoviews unconsistencies #1017

Open sverley opened 1 year ago

sverley commented 1 year ago

ALL software version info

python : 3.9.13 | packaged by conda-forge | (main, May 27 2022, 16:56:21) [GCC 10.3.0] pandas : 1.5.1 holoviews : 1.15.1 hvplot : 0.8.1 bokeh : 2.4.3 matplotlib : 3.6.1

Description of expected behavior and the observed behavior

When I am composing plots build with hvplot (https://hvplot.holoviz.org/user_guide/Plotting.html#composing-plots), it behaves not consistently with some options. Legend has no legend title in composite plot, option like 'legend' doesn't produce any effect with 'matplotlib' extension. And more confusingly, I have to use the holoviews legend_position in composite plots options, not hvplot legend option. I haven't check more options but here are some API discrepancies between hvplot and holoviews modules and bokeh and matplotlib extensions.

I expect that extensions behaves in the same way when composing plots from hvplot. And I think make difference in options name between hvplot and holoviews is very confusing.

In the same way, the alpha= (and not line_alpha=) keywords seems strange with compatibility='bokeh'.

Complete, minimal, self-contained example code that reproduces the issue

import numpy as np
import pandas as pd
import hvplot
import hvplot.pandas
hvplot.extension('bokeh')
index = pd.date_range('1/1/2000', periods=1000)
df = pd.DataFrame(np.random.randn(1000, 4), index=index, columns=list('ABCD')).cumsum()
p1 = df.hvplot(width=400, line_width=4, line_dash='dashed', legend='top')
p2 = df.hvplot(width=400, alpha=0.5, legend='top')
p1 + p2 + p1*p2

produces image while

hvplot.extension('matplotlib', compatibility='bokeh')
index = pd.date_range('1/1/2000', periods=1000)
df = pd.DataFrame(np.random.randn(1000, 4), index=index, columns=list('ABCD')).cumsum()
p1 = df.hvplot(width=400, line_width=4, line_dash='dashed', legend='top')
p2 = df.hvplot(width=400, alpha=0.5, legend='top')
p1 + p2 + p1*p2

image for which you need to specify legend_position (and not legend as hvplot options) to get a similar behavior between matplotlib and bokeh extension.

p1 + p2 + (p1*p2).opts(legend_position='top')

image

maximlt commented 1 year ago

Hi @sverley, thanks for this detailed bug report, that's very helpful.

And I think make difference in options name between hvplot and holoviews is very confusing.

legend in that case is inherited from Pandas' plotting API, that API being the core design of hvPlot, hence the difference with HoloViews.