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 81257c0

Browse filesBrowse files
authored
Merge pull request #15316 from meeseeksmachine/auto-backport-of-pr-15283-on-v3.2.x
Backport PR #15283 on branch v3.2.x (Don't default axes_grid colorbar locator to MaxNLocator.)
2 parents 7f116b2 + 9a10d8c commit 81257c0
Copy full SHA for 81257c0

File tree

Expand file treeCollapse file tree

3 files changed

+24
-14
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+24
-14
lines changed

‎doc/api/prev_api_changes/api_changes_3.2.0/deprecations.rst

Copy file name to clipboardExpand all lines: doc/api/prev_api_changes/api_changes_3.2.0/deprecations.rst
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,14 @@ The main differences are:
4545

4646
- Setting the ticks on the colorbar is done by calling ``colorbar.set_ticks``
4747
rather than ``colorbar.cbar_axis.set_xticks`` or
48-
``colorbar.cbar_axis.set_yticks``.
48+
``colorbar.cbar_axis.set_yticks``; the ``locator`` parameter to ``colorbar()``
49+
is deprecated in favor of its synonym ``ticks`` (which already existed
50+
previously, and is consistent with :mod:`matplotlib.colorbar`).
4951
- The colorbar's long axis is accessed with ``colorbar.xaxis`` or
5052
``colorbar.yaxis`` depending on the orientation, rather than
5153
``colorbar.cbar_axis``.
54+
- The default ticker is no longer ``MaxNLocator(5)``, but a
55+
``_ColorbarAutoLocator``.
5256
- Overdrawing multiple colorbars on top of one another in a single Axes (e.g.
5357
when using the ``cax`` attribute of `~.axes_grid1.axes_grid.ImageGrid`
5458
elements) is not supported; if you previously relied on the second colorbar

‎lib/mpl_toolkits/axes_grid1/axes_grid.py

Copy file name to clipboardExpand all lines: lib/mpl_toolkits/axes_grid1/axes_grid.py
+6-12Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,8 @@ def _tick_only(ax, bottom_on, left_on):
3131

3232
class CbarAxesBase:
3333

34-
def colorbar(self, mappable, *, locator=None, **kwargs):
35-
36-
if locator is None:
37-
if "ticks" not in kwargs:
38-
kwargs["ticks"] = ticker.MaxNLocator(5)
39-
if locator is not None:
40-
if "ticks" in kwargs:
41-
raise ValueError("Either *locator* or *ticks* need" +
42-
" to be given, not both")
43-
else:
44-
kwargs["ticks"] = locator
34+
@cbook._rename_parameter("3.2", "locator", "ticks")
35+
def colorbar(self, mappable, *, ticks=None, **kwargs):
4536

4637
if self.orientation in ["top", "bottom"]:
4738
orientation = "horizontal"
@@ -55,10 +46,13 @@ def colorbar(self, mappable, *, locator=None, **kwargs):
5546
"%(removal)s. Set the 'mpl_toolkits.legacy_colorbar' rcParam "
5647
"to False to use Matplotlib's default colorbar implementation "
5748
"and suppress this deprecation warning.")
49+
if ticks is None:
50+
ticks = ticker.MaxNLocator(5) # For backcompat.
5851
from .colorbar import Colorbar
5952
else:
6053
from matplotlib.colorbar import Colorbar
61-
cb = Colorbar(self, mappable, orientation=orientation, **kwargs)
54+
cb = Colorbar(
55+
self, mappable, orientation=orientation, ticks=ticks, **kwargs)
6256
self._config_axes()
6357

6458
def on_changed(m):

‎lib/mpl_toolkits/tests/test_axes_grid.py

Copy file name to clipboardExpand all lines: lib/mpl_toolkits/tests/test_axes_grid.py
+13-1Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,16 @@ def test_imagegrid_cbar_mode_edge(legacy_colorbar):
4848
# the "second" ones. To achieve this, clear out the axes first.
4949
for ax in grid:
5050
ax.cax.cla()
51-
ax.cax.colorbar(ax.images[0])
51+
cb = ax.cax.colorbar(
52+
ax.images[0],
53+
ticks=mpl.ticker.MaxNLocator(5)) # old default locator.
54+
55+
56+
def test_imagegrid():
57+
mpl.rcParams["mpl_toolkits.legacy_colorbar"] = False
58+
fig = plt.figure()
59+
grid = ImageGrid(fig, 111, nrows_ncols=(1, 1))
60+
ax = grid[0]
61+
im = ax.imshow([[1, 2]], norm=mpl.colors.LogNorm())
62+
cb = ax.cax.colorbar(im)
63+
assert isinstance(cb.locator, mpl.colorbar._ColorbarLogLocator)

0 commit comments

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