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

Support legend label mapping #5322

Closed
jbednar opened this issue May 26, 2022 · 2 comments · Fixed by #5342
Closed

Support legend label mapping #5322

jbednar opened this issue May 26, 2022 · 2 comments · Fixed by #5342
Labels
type: feature A major new feature
Milestone

Comments

@jbednar
Copy link
Member

jbednar commented May 26, 2022

HoloViews automatically constructs legends as color keys when plotting categorical data, now even for datashaded plots:

image

As mentioned in #4806 , in many cases the data itself isn't sufficient to generate such a legend. E.g. in https://examples.pyviz.org/census, the data has a categorical column with 'a' or 'w', but the legend should say 'Asian' or 'White'. Similarly in https://examples.pyviz.org/ship_traffic , the data has a numerical category code, but the legend should say a human-readable value like 'Fishing' or 'Cargo'.

For data like this, it would be useful to be able to supply a legend_labels dictionary option to HoloViews, mapping from a column or dimension value in the data to a human-readable label.

@jbednar jbednar added the TRIAGE Needs triaging label May 26, 2022
@maximlt maximlt added type: feature A major new feature and removed TRIAGE Needs triaging labels Jun 2, 2022
@maximlt maximlt added this to the Wishlist milestone Jun 2, 2022
@korsbakken
Copy link

Does #5342 actually work for all backends? By using the legend_labels option, I get the expected behavior with bokeh, but it appears to have no effect whatsoever with matplotlib.

I test with a figure that has legend labels ('Total', 'Coal', 'Oil', 'Natural gas', 'Oil') to begin with (if I do not use the legend_labels option). The figure is stored in a variable called raw_fig. I test with the following code:

raw_fig.options(
    legend_labels={
        'Natural gas': 'a',
        'Coal': 'b',
        'Other': 'c',
        'Total': 'd',
        'Oil': 'e'
    }
)

With bokeh extension, the legend labels change to a, b, c, d, e as expected. With matplotlib extension and everything else identically the same, they do not. I can also switch back and forth between the two extensions. When bokeh is active, the changed labels are displayed. When matplotlib is active, the original labels are displayed.

I am using the Jupyter Notebook extension in Visual Studio code. with holoviews version 1.15.4 and matplotlib version 3.6.3, running on WSL Ubuntu 20.04 LTS under Windows 11.

Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: feature A major new feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants