Skip to content

Commit 352821e

Browse files
committed
Expire deprecation of AxesDivider defaulting to zero pads.
Note that the semantics of the rcParams are *relative* sizes, so they should be interpreted as such here too.
1 parent 766db51 commit 352821e

File tree

3 files changed

+23
-21
lines changed

3 files changed

+23
-21
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
``AxesDivider`` now defaults to rcParams-specified pads
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
`.AxesDivider.append_axes`, `.AxesDivider.new_horizontal`, and
4+
`.AxesDivider.new_vertical` now default to paddings specified by
5+
:rc:`figure.subplot.wspace` and :rc:`figure.subplot.hspace` rather than zero.

lib/mpl_toolkits/axes_grid1/axes_divider.py

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import numpy as np
66

7+
import matplotlib as mpl
78
from matplotlib import _api
89
from matplotlib.axes import SubplotBase
910
from matplotlib.gridspec import SubplotSpec, GridSpec
@@ -434,11 +435,12 @@ def new_horizontal(self, size, pad=None, pack_start=False, **kwargs):
434435
Parameters
435436
----------
436437
size : :mod:`~mpl_toolkits.axes_grid1.axes_size` or float or str
437-
A width of the axes. If float or string is given, *from_any*
438-
function is used to create the size, with *ref_size* set to AxesX
439-
instance of the current axes.
438+
The axes width. float or str arguments are interpreted as
439+
``axes_size.from_any(size, AxesX(<main_axes>))``.
440440
pad : :mod:`~mpl_toolkits.axes_grid1.axes_size` or float or str
441-
Pad between the axes. It takes same argument as *size*.
441+
Padding between the axes. float or str arguments are interpreted
442+
as ``axes_size.from_any(size, AxesX(<main_axes>))``. Defaults to
443+
:rc:`figure.subplot.wspace` times the main axes width.
442444
pack_start : bool
443445
If False, the new axes is appended at the end
444446
of the list, i.e., it became the right-most axes. If True, it is
@@ -450,10 +452,7 @@ def new_horizontal(self, size, pad=None, pack_start=False, **kwargs):
450452
main axes will be used.
451453
"""
452454
if pad is None:
453-
_api.warn_deprecated(
454-
"3.2", message="In a future version, 'pad' will default to "
455-
"rcParams['figure.subplot.wspace']. Set pad=0 to keep the "
456-
"old behavior.")
455+
pad = mpl.rcParams["figure.subplot.wspace"] * self._xref
457456
if pad:
458457
if not isinstance(pad, Size._Base):
459458
pad = Size.from_any(pad, fraction_ref=self._xref)
@@ -483,11 +482,12 @@ def new_vertical(self, size, pad=None, pack_start=False, **kwargs):
483482
Parameters
484483
----------
485484
size : :mod:`~mpl_toolkits.axes_grid1.axes_size` or float or str
486-
A height of the axes. If float or string is given, *from_any*
487-
function is used to create the size, with *ref_size* set to AxesX
488-
instance of the current axes.
485+
The axes height. float or str arguments are interpreted as
486+
``axes_size.from_any(size, AxesY(<main_axes>))``.
489487
pad : :mod:`~mpl_toolkits.axes_grid1.axes_size` or float or str
490-
Pad between the axes. It takes same argument as *size*.
488+
Padding between the axes. float or str arguments are interpreted
489+
as ``axes_size.from_any(size, AxesY(<main_axes>))``. Defaults to
490+
:rc:`figure.subplot.hspace` times the main axes height.
491491
pack_start : bool
492492
If False, the new axes is appended at the end
493493
of the list, i.e., it became the right-most axes. If True, it is
@@ -499,10 +499,7 @@ def new_vertical(self, size, pad=None, pack_start=False, **kwargs):
499499
main axes will be used.
500500
"""
501501
if pad is None:
502-
_api.warn_deprecated(
503-
"3.2", message="In a future version, 'pad' will default to "
504-
"rcParams['figure.subplot.hspace']. Set pad=0 to keep the "
505-
"old behavior.")
502+
pad = mpl.rcParams["figure.subplot.hspace"] * self._yref
506503
if pad:
507504
if not isinstance(pad, Size._Base):
508505
pad = Size.from_any(pad, fraction_ref=self._yref)

lib/mpl_toolkits/tests/test_axes_grid1.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from itertools import product
22
import platform
33

4-
import matplotlib
4+
import matplotlib as mpl
55
import matplotlib.pyplot as plt
66
from matplotlib import cbook
77
from matplotlib.backend_bases import MouseEvent
@@ -56,9 +56,8 @@ def test_divider_append_axes():
5656
@image_comparison(['twin_axes_empty_and_removed'], extensions=["png"], tol=1)
5757
def test_twin_axes_empty_and_removed():
5858
# Purely cosmetic font changes (avoid overlap)
59-
matplotlib.rcParams.update({"font.size": 8})
60-
matplotlib.rcParams.update({"xtick.labelsize": 8})
61-
matplotlib.rcParams.update({"ytick.labelsize": 8})
59+
mpl.rcParams.update(
60+
{"font.size": 8, "xtick.labelsize": 8, "ytick.labelsize": 8})
6261
generators = ["twinx", "twiny", "twin"]
6362
modifiers = ["", "host invisible", "twin removed", "twin invisible",
6463
"twin removed\nhost invisible"]
@@ -348,7 +347,8 @@ def test_anchored_direction_arrows_many_args():
348347
def test_axes_locatable_position():
349348
fig, ax = plt.subplots()
350349
divider = make_axes_locatable(ax)
351-
cax = divider.append_axes('right', size='5%', pad='2%')
350+
with mpl.rc_context({"figure.subplot.wspace": 0.02}):
351+
cax = divider.append_axes('right', size='5%')
352352
fig.canvas.draw()
353353
assert np.isclose(cax.get_position(original=False).width,
354354
0.03621495327102808)

0 commit comments

Comments
 (0)