Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Bug]: Change in ListedColormap behavior in 3.10.0 #29504

Copy link
Copy link
Open
@jsolbrig

Description

@jsolbrig
Issue body actions

Bug summary

While running integration tests on a package that I maintain I'm seeing a change in the behavior of ListedColormap in 3.10.0. This appears to be a regression and is causing significant changes in some of the imagery that my tests produce.

The tests are baked into a larger system and would be difficult for matplotlib maintainers to replicate, so I wrote up a dummy script that, I think, shows the problem. I'm not sure if it is capturing the full problem or not but it's at least capturing part of it.

Code for reproduction

import numpy as np
from matplotlib import pyplot as plt
from matplotlib.colors import ListedColormap
from matplotlib import __version__ as mpl_vers


cld_type_colors = [
    "ghostwhite",
    "slategray",
    "blue",
    "royalblue",
    "cyan",
    "limegreen",
    "green",
    "yellow",
    "gold",
    "lightsalmon",
    "coral",
    "red",
    "maroon",
    "black",
]


rainbow_colors = [
    (255, 0, 0),     # Red
    (255, 64, 0),    # Reddish-Orange
    (255, 128, 0),   # Orange
    (255, 192, 0),   # Yellowish-Orange
    (255, 255, 0),   # Yellow
    (192, 255, 0),   # Yellowish-Green
    (128, 255, 0),   # Greenish-Yellow
    (0, 255, 0),     # Green
    (0, 255, 128),   # Greenish-Cyan
    (0, 255, 192),   # Cyan
    (0, 255, 255),   # Bright Cyan
    (0, 192, 255),   # Bluish-Cyan
    (0, 128, 255),   # Blue
    (0, 64, 255),    # Blueish-Purple
    (64, 0, 255),    # Purple
    (128, 0, 255),   # Violet
]
rainbow_colors = [(r / 255, g / 255, b / 255) for r, g, b in rainbow_colors]

cld_type_cmap = ListedColormap(cld_type_colors, name="cld_type_cmap")
rainbow_cmap = ListedColormap(rainbow_colors, name="rainbow_cmap")

# Create 1600x1600 array constant values in the vertial and float values ranging from
# 0-15 in the horizontal
size = 1600
num_values = 16
h_vals = np.linspace(0, num_values - 1, size)
flt_array = np.tile(h_vals, (size, 1))

# Plot float values using the cloud type colormap
fig, ax = plt.subplots(figsize=(10, 10))
ax.set_title("Float - Cloud Type Color Map - MPL Version: " + mpl_vers)
ax.imshow(flt_array, cmap=cld_type_cmap)
fig.savefig(f"float_cloud_type_{mpl_vers.replace('.', '')}.png")

# Plot float values using the rainbow colormap
fig, ax = plt.subplots(figsize=(10, 10))
ax.set_title("float - Rainbow Color Map - MPL Version: " + mpl_vers)
ax.imshow(flt_array, cmap=rainbow_cmap)
fig.savefig(f"float_rainbow_{mpl_vers.replace('.', '')}.png")

# Create a 1600x1600 array constant values in the vertial and integer values ranging
# from 0-15 in the horizontal
h_vals = np.arange(0, 16)
h_vals = np.repeat(h_vals, size // len(h_vals))
int_array = np.tile(h_vals, (size, 1))

# Plot integer values using the cloud type colormap
fig, ax = plt.subplots(figsize=(10, 10))
ax.set_title("Integer - Cloud Type Color Map - MPL Version: " + mpl_vers)
ax.imshow(int_array, cmap=cld_type_cmap)
fig.savefig(f"int_cloud_type_{mpl_vers.replace('.', '')}.png")

# Plot integer values using the rainbow colormap
fig, ax = plt.subplots(figsize=(10, 10))
ax.set_title("Integer - Rainbow Color Map - MPL Version: " + mpl_vers)
ax.imshow(int_array, cmap=rainbow_cmap)
fig.savefig(f"int_rainbow_{mpl_vers.replace('.', '')}.png")

Actual outcome

With v3.10.0 I get the following images. If you zoom in on the borders between color bands, you will see some lines of different color.

Image

Image

Image

Image

Zoomed in:

Image

Image

Image

Image

Expected outcome

With v3.9.4 I get the following output. If you zoom in on the borders between the color bands, there is a sharp transition between bands with no extra colors.

Image

Image

Image

Image

Zoomed in:

Image

Image

Image

Image

Additional information

Just for additional context, below are the really ugly images produced by our integration tests. The changes in how the colormaps are applied appear to be the cause of some of the differences here, though I don't think they actually address everything.

3.10.0

Image

3.9.4

Image

Operating system

Rocky

Matplotlib Version

3.10.0

Matplotlib Backend

agg

Python version

3.10.16

Jupyter version

No response

Installation

pip

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

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.