Skip to content

Feature: make exact evaluation of function-defined colormaps accessible #157

Description

@matthiasschabel

Colormap.__call__ always goes through a 256-entry LUT, so a colormap defined by a function (ColorStops(lut_func=...), e.g. prism, flag, gnuplot, cubehelix) cannot be evaluated exactly at an arbitrary position through the public API. The function itself is only reachable as the private ColorStops._lut_func, and color_stops.stops holds a 256-point sampling of it.

import numpy as np
from cmap import Colormap

cm = Colormap("prism")
x = np.array([0.1234])
print(cm(x)[0, :3])                               
print(cm.color_stops._call_lut_func(x)[0, :3])    
[1.     0.9237 0.    ]
[1.     0.9744 0.    ]

lut(n) already evaluates the function directly at any n but there's no public entry point for arbitrary x. Either a public read-only ColorStops.lut_func property or an N=None option on Colormap.__call__ that evaluates lut_func when it exists would be nice...

Activity

  1. tlambert03 commented on Oct 1, 2026

    @tlambert03
    Member

    I agree, and I'm open to either solution. The public accessor is a little more explicit, but also a bit more "different" for the user wanting a color mapped at an arbitrary location. N=None is nice for the single entry point, but slightly more magic. I'm open to either. You have a preference?

  2. matthiasschabel commented on Oct 1, 2026

    @matthiasschabel
    ContributorAuthor

    Despite wanting to push the magic solution, I think just making the accessor public is the more responsible option. That wouldn't preclude adding the N=None approach later if there was a compelling reason/demand for it...

  3. tlambert03 commented on Oct 2, 2026

    @tlambert03
    Member

    Sounds good to me, would you be able to make that PR?

  4. matthiasschabel commented on Oct 2, 2026

    @matthiasschabel
    ContributorAuthor
  5. matthiasschabel commented on Oct 2, 2026

    @matthiasschabel
    ContributorAuthor
  6. tlambert03 commented on Oct 2, 2026

    @tlambert03
    Member

    commented there, i'm ok with it 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions