FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[Bug]: LinearSegmentedColormap returns different results for int/float when used as a function · Issue #29487 · matplotlib/matplotlib · GitHub

Repository navigation

[Bug]: LinearSegmentedColormap returns different results for int/float when used as a function #29487

Description

Bug summary

When invoking a LinearSegmentedColormap  object as a function, the output can differ based on whether you pass an integer or a float.

For example, in the code snippet below, cmap(1) returns a completely different result than cmap(1.0). While this behavior might be expected given how the colormap is implemented, it feels unintuitive.

IMO the provided reprex demonstrates the issue clearly, but please let me know if more details are needed.

Code for reproduction

from matplotlib.colors import LinearSegmentedColormap

cmap = LinearSegmentedColormap.from_list(name="reprex", colors=["red", "blue"])
print("cmap(0):", cmap(0))
print("cmap(1):", cmap(1))
print("cmap(1.0):", cmap(1.0))

Actual outcome

cmap(0): (np.float64(1.0), np.float64(0.0), np.float64(0.0), np.float64(1.0)) (red)
cmap(1): (np.float64(0.996078431372549), np.float64(0.0), np.float64(0.00392156862745098), np.float64(1.0)) (red)
cmap(1.0): (np.float64(0.0), np.float64(0.0), np.float64(1.0), np.float64(1.0)) (blue)

Expected outcome

cmap(0): (np.float64(1.0), np.float64(0.0), np.float64(0.0), np.float64(1.0)) (red)
cmap(1): (np.float64(0.0), np.float64(0.0), np.float64(1.0), np.float64(1.0)) (blue)
cmap(1.0): (np.float64(0.0), np.float64(0.0), np.float64(1.0), np.float64(1.0)) (blue)

Additional information

No response

Operating system

MacOS Sonoma 14.6.1

Matplotlib Version

3.10.0

Matplotlib Backend

module://positron_ipykernel.matplotlib_backend

Python version

Python 3.13.1

Jupyter version

/

Installation

pip

Activity

  1. timhoffm commented on Jan 20, 2025

    Member

    This is a duplicate of #28198.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL