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

Commit 884397a

Browse filesBrowse files
authored
Merge pull request #24088 from jklymak/fix-deprecate-colorbar-orphan
MNT: make orphaned colorbar deprecate versus raise
2 parents 7f758c6 + 7fb75e0 commit 884397a
Copy full SHA for 884397a

File tree

Expand file treeCollapse file tree

2 files changed

+8
-3
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+8
-3
lines changed

‎lib/matplotlib/figure.py

Copy file name to clipboardExpand all lines: lib/matplotlib/figure.py
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,11 +1253,13 @@ def colorbar(
12531253
# Store the value of gca so that we can set it back later on.
12541254
if cax is None:
12551255
if ax is None:
1256-
raise ValueError(
1256+
_api.warn_deprecated("3.6", message=(
12571257
'Unable to determine Axes to steal space for Colorbar. '
1258+
'Using gca(), but will raise in the future. '
12581259
'Either provide the *cax* argument to use as the Axes for '
12591260
'the Colorbar, provide the *ax* argument to steal space '
1260-
'from it, or add *mappable* to an Axes.')
1261+
'from it, or add *mappable* to an Axes.'))
1262+
ax = self.gca()
12611263
current_ax = self.gca()
12621264
userax = False
12631265
if (use_gridspec and isinstance(ax, SubplotBase)):

‎lib/matplotlib/tests/test_colorbar.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_colorbar.py
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import numpy as np
22
import pytest
33

4+
from matplotlib import _api
45
from matplotlib import cm
56
import matplotlib.colors as mcolors
67
import matplotlib as mpl
78

9+
810
from matplotlib import rc_context
911
from matplotlib.testing.decorators import image_comparison
1012
import matplotlib.pyplot as plt
@@ -319,7 +321,8 @@ def test_parentless_mappable():
319321
pc = mpl.collections.PatchCollection([], cmap=plt.get_cmap('viridis'))
320322
pc.set_array([])
321323

322-
with pytest.raises(ValueError, match='Unable to determine Axes to steal'):
324+
with pytest.warns(_api.MatplotlibDeprecationWarning,
325+
match='Unable to determine Axes to steal'):
323326
plt.colorbar(pc)
324327

325328

0 commit comments

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