8000 Merge pull request #20064 from anntzer/adp · matplotlib/matplotlib@679ca17 · GitHub
[go: up one dir, main page]

Skip to content

Commit 679ca17

Browse files
authored
Merge pull request #20064 from anntzer/adp
Expire deprecation of AxesDivider defaulting to zero pads.
2 parents a94acb3 + 352821e commit 679ca17

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
@@ -426,11 +427,12 @@ def new_horizontal(self, size, pad=None, pack_start=False, **kwargs):
426427
Parameters
427428
----------
428429
size : :mod:`~mpl_toolkits.axes_grid1.axes_size` or float or str
429-
A width of the axes. If float or string is given, *from_any*
430-
function is used to create the size, with *ref_size* set to AxesX
431-
instance of the current axes.
430+
The axes width. float or str arguments are interpreted as
431+
``axes_size.from_any(size, AxesX(<main_axes>))``.
432432
pad : :mod:`~mpl_toolkits.axes_grid1.axes_size` or float or str
433-
Pad between the axes. It takes same argument as *size*.
433+
Padding between the axes. float or str arguments are interpreted
434+
as ``axes_size.from_any(size, AxesX(<main_axes>))``. Defaults to
435+
:rc:`figure.subplot.wspace` times the main axes width.
434436
pack_start : bool
435437
If False, the new axes is appended at the end
436438
of the list, i.e., it became the right-most axes. If True, it is
@@ -442,10 +444,7 @@ def new_horizontal(self, size, pad=None, pack_start=False, **kwargs):
442444
main axes will be used.
443445
"""
444446
if pad is None:
445-
_api.warn_deprecated(
446-
"3.2", message="In a future version, 'pad' will default to "
447-
"rcParams['figure.subplot.wspace']. Set pad=0 to keep the "
448-
"old behavior.")
447+
pad = mpl.rcParams["figure.subplot.wspace"] * self._xref
449448
if pad:
450449
if not isinstance(pad, Size._Base):
451450
pad = Size.from_any(pad, fraction_ref=self._xref)
@@ -475,11 +474,12 @@ def new_vertical(self, size, pad=None, pack_start=False, **kwargs):
475474
Parameters
476475
----------
477476
size : :mod:`~mpl_toolkits.axes_grid1.axes_size` or float or str
478-
A height of the axes. If float or string is given, *from_any*
479-
function is used to create the size, with *ref_size* set to AxesX
480-
instance of the current axes.
477+
The axes height. float or str arguments are interpreted as
478+
``axes_size.from_any(size, AxesY(<main_axes>))``.
481479
pad : :mod:`~mpl_toolkits.axes_grid1.axes_size` or float or str
482-
Pad between the axes. It takes same argument as *size*.
480+
Padding between the axes. float or str arguments are interpreted
481+
as ``axes_size.from_any(size, AxesY(<main_axes>))``. Defaults to
482+
:rc:`figure.subplot.hspace` times the main axes height.
483483
pack_start : bool
484484
If False, the new axes is appended at the end
485485
of the list, i.e., it became the right-most axes. If True, it is
@@ -491,10 +491,7 @@ def new_vertical(self, size, pad=None, pack_start=False, **kwargs):
491491
main axes will be used.
492492
"""
493493
if pad is None:
494-
_api.warn_deprecated(
495-
"3.2", message="In a future version, 'pad' will default to "
496-
"rcParams['figure.subplot.hspace']. Set pad=0 to keep the "
497-
"old behavior.")
494+
pad = mpl.rcParams["figure.subplot.hspace"] * self._yref
498495
if pad:
499496
if not isinstance(pad, Size._Base):
500497
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
6250 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)
0