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

Exposing some options as enums? #1498

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

Exposing some options as enums? #1498

maximlt opened this issue Feb 13, 2025 · 0 comments
Labels

Comments

@maximlt
Copy link
Member

maximlt commented Feb 13, 2025

There are a number of keywords that accept a set of values (usually strings). In HoloViews, they are usually declared in a Selector Parameter, so they are more organized and more exposed than in hvPlot which doesn't use Param.

Here's a non-exhaustive list:

Customization:

  • xaxis/yaxis: e.g. top, bottom, right, left
  • legend: top, bottom, right, left
  • tools: e.g. tap, box_select
  • hover: vline, hline
  • widget_location

Downsampling:

  • aggregator: e.g. mean, count, min, max,
  • downsample: e.g. lttb, minmax, m4

Geographic:

  • coastline: e.g. 10m, 50m
  • features: e.g. borders, lakes

I would like to discuss whether having them available as Enums in hvPlot would help improve the user experience. As suggested by @ahuang11, if we were to rely on Enums they should probably be first added to HoloViews. Here's the sort of change we could make in HoloViews, adding an Enum for legend_position and updating the Parameter in a way that doesn't change it at all.

# holoviews/plotting/enums.py
from enum import Enum
import param

class LEGEND_POSITION(str, Enum):
    TOP_RIGHT = 'top_right'
    TOP_LEFT = 'top_left'
    BOTTOM_LEFT = 'bottom_left'
    RIGHT = 'right'
    LEFT = 'left'
    TOP = 'top'
    BOTTOM = 'bottom'

# HoloViews plotting modules
class Element(param.Parameterized):
    legend_position = param.Selector(objects=[member.value for member in LEGEND_POSITION])

hvPlot could expose the Enums in its top-level module.

# hvplot.__init__.py
from hv.plotting.enums import LEGEND_POSITION as LEGEND

So users can leverage them easily:

# USER CODE
import hvplot.pandas
from bokeh.sampledata.penguins import data as df

df.hvplot.scatter(x='bill_length_mm', y='bill_depth_mm', by='species', legend=hvplot.LEGEND.TOP_RIGHT)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant