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

Skip to content

MNT: make orphaned colorbar deprecate versus raise #24088

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 6, 2022
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
6 changes: 4 additions & 2 deletions lib/matplotlib/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -1253,11 +1253,13 @@ def colorbar(
# Store the value of gca so that we can set it back later on.
if cax is None:
if ax is None:
raise ValueError(
_api.warn_deprecated("3.6", message=(
'Unable to determine Axes to steal space for Colorbar. '
'Using gca(), but will raise in the future. '
'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.')
'from it, or add *mappable* to an Axes.'))
ax = self.gca()
current_ax = self.gca()
userax = False
if (use_gridspec and isinstance(ax, SubplotBase)):
Expand Down
5 changes: 4 additions & 1 deletion lib/matplotlib/tests/test_colorbar.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import numpy as np
import pytest

from matplotlib import _api
from matplotlib import cm
import matplotlib.colors as mcolors
import matplotlib as mpl


from matplotlib import rc_context
from matplotlib.testing.decorators import image_comparison
import matplotlib.pyplot as plt
Expand Down Expand Up @@ -319,7 +321,8 @@ def test_parentless_mappable():
pc = mpl.collections.PatchCollection([], cmap=plt.get_cmap('viridis'))
pc.set_array([])

with pytest.raises(ValueError, match='Unable to determine Axes to steal'):
with pytest.warns(_api.MatplotlibDeprecationWarning,
match='Unable to determine Axes to steal'):
plt.colorbar(pc)


Expand Down