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
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
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