Skip to content

Commit 68d6b79

Browse files
authored
Merge pull request #20117 from anntzer/nhv
Very soft-deprecate AxesDivider.new_{horizontal,vertical}.
2 parents d8a90ae + 6447c95 commit 68d6b79

File tree

4 files changed

+42
-56
lines changed

4 files changed

+42
-56
lines changed

doc/api/prev_api_changes/api_changes_3.5.0/behaviour.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,6 @@ location of values that lie between two levels.
242242
``AxesDivider`` now defaults to rcParams-specified pads
243243
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
244244

245-
`.AxesDivider.append_axes`, `.AxesDivider.new_horizontal`, and
246-
`.AxesDivider.new_vertical` now default to paddings specified by
245+
`.AxesDivider.append_axes`, ``AxesDivider.new_horizontal``, and
246+
``AxesDivider.new_vertical`` now default to paddings specified by
247247
:rc:`figure.subplot.wspace` and :rc:`figure.subplot.hspace` rather than zero.

examples/axes_grid1/demo_axes_divider.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def demo_locatable_axes_easy(ax):
6868

6969
divider = make_axes_locatable(ax)
7070

71-
ax_cb = divider.new_horizontal(size="5%", pad=0.05)
71+
ax_cb = divider.append_axes("right", size="5%", pad=0.05)
7272
fig = ax.get_figure()
7373
fig.add_axes(ax_cb)
7474

@@ -86,7 +86,7 @@ def demo_images_side_by_side(ax):
8686
divider = make_axes_locatable(ax)
8787

8888
Z, extent = get_demo_image()
89-
ax2 = divider.new_horizontal(size="100%", pad=0.05)
89+
ax2 = divider.append_axes("right", size="100%", pad=0.05)
9090
fig1 = ax.get_figure()
9191
fig1.add_axes(ax2)
9292

examples/axes_grid1/make_room_for_ylabel_using_axesgrid.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
ax1 = plt.axes([0, 0, 1, 1])
4141
divider = make_axes_locatable(ax1)
4242

43-
ax2 = divider.new_horizontal("100%", pad=0.3, sharey=ax1)
43+
ax2 = divider.append_axes("right", "100%", pad=0.3, sharey=ax1)
4444
ax2.tick_params(labelleft=False)
4545
fig.add_axes(ax2)
4646

lib/mpl_toolkits/axes_grid1/axes_divider.py

+37-51
Original file line numberDiff line numberDiff line change
@@ -441,26 +441,11 @@ def _get_new_axes(self, *, axes_class=None, **kwargs):
441441

442442
def new_horizontal(self, size, pad=None, pack_start=False, **kwargs):
443443
"""
444-
Add a new axes on the right (or left) side of the main axes.
444+
Helper method for ``append_axes("left")`` and ``append_axes("right")``.
445445
446-
Parameters
447-
----------
448-
size : :mod:`~mpl_toolkits.axes_grid1.axes_size` or float or str
449-
The axes width. float or str arguments are interpreted as
450-
``axes_size.from_any(size, AxesX(<main_axes>))``.
451-
pad : :mod:`~mpl_toolkits.axes_grid1.axes_size` or float or str
452-
Padding between the axes. float or str arguments are interpreted
453-
as ``axes_size.from_any(size, AxesX(<main_axes>))``. Defaults to
454-
:rc:`figure.subplot.wspace` times the main axes width.
455-
pack_start : bool
456-
If False, the new axes is appended at the end
457-
of the list, i.e., it became the right-most axes. If True, it is
458-
inserted at the start of the list, and becomes the left-most axes.
459-
**kwargs
460-
All extra keywords arguments are passed to the created axes.
461-
If *axes_class* is given, the new axes will be created as an
462-
instance of the given class. Otherwise, the same class of the
463-
main axes will be used.
446+
See the documentation of `append_axes` for more details.
447+
448+
:meta private:
464449
"""
465450
if pad is None:
466451
pad = mpl.rcParams["figure.subplot.wspace"] * self._xref
@@ -488,26 +473,11 @@ def new_horizontal(self, size, pad=None, pack_start=False, **kwargs):
488473

489474
def new_vertical(self, size, pad=None, pack_start=False, **kwargs):
490475
"""
491-
Add a new axes on the top (or bottom) side of the main axes.
476+
Helper method for ``append_axes("top")`` and ``append_axes("bottom")``.
492477
493-
Parameters
494-
----------
495-
size : :mod:`~mpl_toolkits.axes_grid1.axes_size` or float or str
496-
The axes height. float or str arguments are interpreted as
497-
``axes_size.from_any(size, AxesY(<main_axes>))``.
498-
pad : :mod:`~mpl_toolkits.axes_grid1.axes_size` or float or str
499-
Padding between the axes. float or str arguments are interpreted
500-
as ``axes_size.from_any(size, AxesY(<main_axes>))``. Defaults to
501-
:rc:`figure.subplot.hspace` times the main axes height.
502-
pack_start : bool
503-
If False, the new axes is appended at the end
504-
of the list, i.e., it became the right-most axes. If True, it is
505-
inserted at the start of the list, and becomes the left-most axes.
506-
**kwargs
507-
All extra keywords arguments are passed to the created axes.
508-
If *axes_class* is given, the new axes will be created as an
509-
instance of the given class. Otherwise, the same class of the
510-
main axes will be used.
478+
See the documentation of `append_axes` for more details.
479+
480+
:meta private:
511481
"""
512482
if pad is None:
513483
pad = mpl.rcParams["figure.subplot.hspace"] * self._yref
@@ -528,31 +498,47 @@ def new_vertical(self, size, pad=None, pack_start=False, **kwargs):
528498
else:
529499
self._vertical.append(size)
530500
locator = self.new_locator(
531-
nx=self._xrefindex, ny=len(self._vertical)-1)
501+
nx=self._xrefindex, ny=len(self._vertical) - 1)
532502
ax = self._get_new_axes(**kwargs)
533503
ax.set_axes_locator(locator)
534504
return ax
535505

536506
@_api.delete_parameter("3.5", "add_to_figure", alternative="ax.remove()")
537-
def append_axes(self, position, size, pad=None, add_to_figure=True,
538-
**kwargs):
507+
def append_axes(self, position, size, pad=None, add_to_figure=True, *,
508+
axes_class=None, **kwargs):
539509
"""
540-
Create an axes at the given *position* with the same height
541-
(or width) of the main axes.
542-
543-
*position*
544-
["left"|"right"|"bottom"|"top"]
510+
Add a new axes on a given side of the main axes.
545511
546-
*size* and *pad* should be axes_grid.axes_size compatible.
512+
Parameters
513+
----------
514+
position : {"left", "right", "bottom", "top"}
515+
Where the new axes is positioned relative to the main axes.
516+
size : :mod:`~mpl_toolkits.axes_grid1.axes_size` or float or str
517+
The axes width or height. float or str arguments are interpreted
518+
as ``axes_size.from_any(size, AxesX(<main_axes>))`` for left or
519+
right axes, and likewise with ``AxesY`` for bottom or top axes.
520+
pad : :mod:`~mpl_toolkits.axes_grid1.axes_size` or float or str
521+
Padding between the axes. float or str arguments are interpreted
522+
as for *size*. Defaults to :rc:`figure.subplot.wspace` times the
523+
main axes width (left or right axes) or :rc:`figure.subplot.hspace`
524+
times the main axes height (bottom or top axes).
525+
axes_class : subclass type of `~.axes.Axes`, optional
526+
The type of the new axes. Defaults to the type of the main axes.
527+
**kwargs
528+
All extra keywords arguments are passed to the created axes.
547529
"""
548530
if position == "left":
549-
ax = self.new_horizontal(size, pad, pack_start=True, **kwargs)
531+
ax = self.new_horizontal(
532+
size, pad, pack_start=True, axes_class=axes_class, **kwargs)
550533
elif position == "right":
551-
ax = self.new_horizontal(size, pad, pack_start=False, **kwargs)
534+
ax = self.new_horizontal(
535+
size, pad, pack_start=False, axes_class=axes_class, **kwargs)
552536
elif position == "bottom":
553-
ax = self.new_vertical(size, pad, pack_start=True, **kwargs)
537+
ax = self.new_vertical(
538+
size, pad, pack_start=True, axes_class=axes_class, **kwargs)
554539
elif position == "top":
555-
ax = self.new_vertical(size, pad, pack_start=False, **kwargs)
540+
ax = self.new_vertical(
541+
size, pad, pack_start=False, axes_class=axes_class, **kwargs)
556542
else:
557543
_api.check_in_list(["left", "right", "bottom", "top"],
558544
position=position)

0 commit comments

Comments
 (0)