Skip to content

[Bug]: Matplotlib is unable to apply the boundaries in the colorbar after updating to 3.5.0 #21909

@krysros

Description

@krysros

Bug summary

Matplotlib is unable to apply the boundaries in the colorbar after updating to 3.5.0. Please compare the results in the screenshots between version 3.5.0 and the previous version 3.4.3.

Code for reproduction

import matplotlib.pyplot as plt
import numpy as np
from matplotlib import cm

n_radii = 8
n_angles = 36

# Make radii and angles spaces (radius r=0 omitted to eliminate duplication).
radii = np.linspace(0.125, 1.0, n_radii)
angles = np.linspace(0, 2*np.pi, n_angles, endpoint=False)[..., np.newaxis]

# Convert polar (radii, angles) coords to cartesian (x, y) coords.
# (0, 0) is manually added at this stage,  so there will be no duplicate
# points in the (x, y) plane.
x = np.append(0, (radii*np.cos(angles)).flatten())
y = np.append(0, (radii*np.sin(angles)).flatten())

# Compute z to make the pringle surface.
z = np.sin(-x*y)

fig, ax = plt.subplots(subplot_kw={"projection": "3d"})

surf = ax.plot_trisurf(x, y, z, linewidth=0.2, antialiased=True, cmap=cm.coolwarm)

boundaries = np.linspace(np.min(z), np.max(z), 10, endpoint=True)
fig.colorbar(surf, shrink=0.5, boundaries=boundaries, pad=0.1)

plt.show()

Actual outcome

Figure_matplotlib==3 5 0

Expected outcome

Figure_matplotlib==3 4 3

Additional information

No response

Operating system

Windows

Matplotlib Version

3.5.0

Matplotlib Backend

TkAgg

Python version

Python 3.9.9, Python 3.10.1

Jupyter version

No response

Installation

pip

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions