8000 [Bug]: ValueError: Unable to determine Axes to steal space for Colorbar. · Issue #23973 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
[Bug]: ValueError: Unable to determine Axes to steal space for Colorbar. #23973
Closed
@janosh

Description

@janosh

Bug summary

matplotlib==3.6.0 started raising an error when trying to add a colorbar to plt.hist():

ValueError: Unable to determine Axes to steal space for Colorbar. Either provide the cax argument to use as the Axes for the Colorbar, provide the ax argument to steal space from it, or add mappable to an Axes.

Code for reproduction

import matplotlib.pyplot as plt
import numpy as np

xs = np.random.rand(100)

_, bin_edges, bars = plt.hist(xs)
color_map = getattr(plt.cm, "hot")
for x_val, rect in zip(bin_edges, bars.patches):
    rect.set_color(color_map(x_val))

cbar = plt.colorbar(
    plt.cm.ScalarMappable(cmap=color_map),
    # cax=ax.inset_axes([0.95, 0.1, 0.05, 0.8]),
)

Actual outcome

In matplotlib==3.6.0:

mpl==3 6 0

Expected outcome

In matplotlib==3.5.1:

mpl==3 5 1

Operating system

macOS 12.6

Matplotlib Version

3.6.0

Python version

3.10

Installation

pip

Metadata

Metadata

Assignees

No one assigned

    Labels

    Release criticalFor bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.topic: color/colorbar

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0