Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 06ecfd4

Browse files
committed
MNT: make orphaned colorbar depreacte versus raise
1 parent 0517187 commit 06ecfd4

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

lib/matplotlib/figure.py

Lines 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

Lines 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)