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

Crash in extend_colormap when colormap contains more colors than requested #12

Open
pavlin-policar opened this issue Feb 15, 2024 · 0 comments

Comments

@pavlin-policar
Copy link

Thanks for the nice library. I've come across a bug that occurrs when I want to extend a matplotlib colormap, e.g., tab10, but request fewer colors than the initial colormap contains.

For instance

glasbey.extend_palette("tab10", 10)
glasbey.extend_palette("tab10", 15)

both work fine, but if I request something <10, e.g.,

glasbey.extend_palette("tab10", 5)

I get the following error

ValueError                                Traceback (most recent call last)
Input In [24], in <cell line: 2>()
      1 import glasbey
----> 2 glasbey.extend_palette("tab10", 5)

File ~/miniconda3/envs/ml/lib/python3.10/site-packages/glasbey/_glasbey.py:338, in extend_palette(palette, palette_size, grid_size, as_hex, grid_space, lightness_bounds, chroma_bounds, hue_bounds, red_bounds, green_bounds, blue_bounds, colorblind_safe, cvd_type, cvd_severity)
    334 if not colorblind_safe:
    335     palette = cspace_convert(palette, "sRGB1", "CAM02-UCS").astype(
    336         np.float32, order="C"
    337     )
--> 338     palette = generate_palette_cam02ucs(colors, palette, np.uint32(palette_size))
    339 else:
    340     cvd_space = {
    341         "name": "sRGB1+CVD",
    342         "cvd_type": cvd_type,
    343         "severity": cvd_severity,
    344     }

ValueError: cannot assign slice from input of different size

I understand that it makes no sense to actually call this function when the colormap contains enough colors, but I'm trying to integrate this into my plotting utils where the number of colors I need can be highly variable, so this would be a "nice to have". If nothing else, a less crpytic error would be preferrable.

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

No branches or pull requests

1 participant