Clarify error for colorbar with unparented mappable by QuLogic · Pull Request #23740 · matplotlib/matplotlib · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion doc/api/next_api_changes/removals/22081-AL.rst
8 changes: 7 additions & 1 deletion lib/matplotlib/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -1245,13 +1245,19 @@ def colorbar(
"""

if ax is None:
ax = getattr(mappable, "axes", self.gca())
ax = getattr(mappable, "axes", None)

if (self.get_layout_engine() is not None and
not self.get_layout_engine().colorbar_gridspec):
use_gridspec = False
# Store the value of gca so that we can set it back later on.
if cax is None:
if ax is None:
raise 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.')
current_ax = self.gca()
userax = False
if (use_gridspec and isinstance(ax, SubplotBase)):
Expand Down
10 changes: 9 additions & 1 deletion lib/matplotlib/tests/test_colorbar.py