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

Inconsistency with categorical coloring using different cmaps #6505

Open
1 task
Azaya89 opened this issue Jan 31, 2025 · 1 comment
Open
1 task

Inconsistency with categorical coloring using different cmaps #6505

Azaya89 opened this issue Jan 31, 2025 · 1 comment
Labels
TRIAGE Needs triaging

Comments

@Azaya89
Copy link
Contributor

Azaya89 commented Jan 31, 2025

ALL software version info

Software Version Info
HoloViews = 1.20.1a0
bokeh = 3.6.2
matplotlib = 3.10.0

Description of expected behavior and the observed behavior

Expected behavior
I expect the colormaps in categorical plots to map to categories of the plot consistently

Observed behavior
Depending on the type of colormap used, the colors are parsed either linearly or categorically, sometimes even with the same type of colormap

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

Some data

import pandas as pd, holoviews as hv, numpy as np

hv.extension('bokeh')
hv.opts.defaults(hv.opts.Points(width=400, height=300, xaxis=None, yaxis=None))

N_POINTS_PER_GROUP = 1_000
GRID_DIM = 3

data_frames = [
    pd.DataFrame({
        'x': np.random.normal(j, 0.25, N_POINTS_PER_GROUP),
        'y': np.random.normal(i, 0.25, N_POINTS_PER_GROUP),
        'cat': f'cat{GRID_DIM * i + j}'
    })
    for i in range(GRID_DIM) for j in range(GRID_DIM)
]

df = pd.concat(data_frames, ignore_index=True)

Using colorcet cmaps

import colorcet as cc

hv.Points(df, ['x', 'y']).opts(color='cat', cmap=cc.bwy) # a list of hex colors

Output
Colors are parsed linearly (Unexpected. Not ideal)

Image

hv.Points(df, ['x', 'y']).opts(color='cat', cmap='bwy') # string value

Output
Colors are parsed categorically (Expected)

Image

However, this passing of string names doesn't always work as expected:

hv.Points(df, ['x', 'y']).opts(color='cat', cmap='viridis')

Image

Using bokeh color palette directly also doesn't work as expected

from bokeh.palettes import Viridis256 # a tuple of hex colors

hv.Points(df, ['x', 'y']).opts(color='cat', cmap=Viridis256)

Image

Matplotlib ListedColormap works

from matplotlib import colormaps

hv.Points(df, ['x', 'y']).opts(color='cat', cmap=colormaps['viridis']) # ListedColormap object

Image

Stack traceback and/or browser JavaScript console output

None

  • I may be interested in making a pull request to address this
@Azaya89 Azaya89 added the TRIAGE Needs triaging label Jan 31, 2025
@ahuang11
Copy link
Collaborator

ahuang11 commented Feb 3, 2025

What if you set color_levels opts

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

No branches or pull requests

2 participants