Skip to content

Commit 6447c95

Browse files
committed
Very soft-deprecate AxesDivider.new_{horizontal,vertical}.
`append_axes` is a more general API which is basically just as ergonomic, and avoids exposing the slightly unusual feature of axes_grid having indices increasing towards the top for vertical stacks (contrary to gridspec which goes towards the bottom), and hence `new_vertical(append_start={True,False})` behaving in the opposite direction as one may naively expect. Given that `new_horizontal` and `new_vertical` would basically stay as helpers, it seems overkill to deprecate them, but perhaps we can at least hide them from the docs (`:meta private:`). Also promote `axes_class` to be a plain normal parameter.
1 parent 8a8dd90 commit 6447c95

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
@@ -442,26 +442,11 @@ def _get_new_axes(self, *, axes_class=None, **kwargs):
442442

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

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

537507
@_api.delete_parameter("3.5", "add_to_figure", alternative="ax.remove()")
538-
def append_axes(self, position, size, pad=None, add_to_figure=True,
539-
**kwargs):
508+
def append_axes(self, position, size, pad=None, add_to_figure=True, *,
509+
axes_class=None, **kwargs):
540510
"""
541-
Create an axes at the given *position* with the same height
542-
(or width) of the main axes.
543-
544-
*position*
545-
["left"|"right"|"bottom"|"top"]
511+
Add a new axes on a given side of the main axes.
546512
547-
*size* and *pad* should be axes_grid.axes_size compatible.
513+
Parameters
514+
----------
515+
position : {"left", "right", "bottom", "top"}
516+
Where the new axes is positioned relative to the main axes.
517+
size : :mod:`~mpl_toolkits.axes_grid1.axes_size` or float or str
518+
The axes width or height. float or str arguments are interpreted
519+
as ``axes_size.from_any(size, AxesX(<main_axes>))`` for left or
520+
right axes, and likewise with ``AxesY`` for bottom or top axes.
521+
pad : :mod:`~mpl_toolkits.axes_grid1.axes_size` or float or str
522+
Padding between the axes. float or str arguments are interpreted
523+
as for *size*. Defaults to :rc:`figure.subplot.wspace` times the
524+
main axes width (left or right axes) or :rc:`figure.subplot.hspace`
525+
times the main axes height (bottom or top axes).
526+
axes_class : subclass type of `~.axes.Axes`, optional
527+
The type of the new axes. Defaults to the type of the main axes.
528+
**kwargs
529+
All extra keywords arguments are passed to the created axes.
548530
"""
549531
if position == "left":
550-
ax = self.new_horizontal(size, pad, pack_start=True, **kwargs)
532+
ax = self.new_horizontal(
533+
size, pad, pack_start=True, axes_class=axes_class, **kwargs)
551534
elif position == "right":
552-
ax = self.new_horizontal(size, pad, pack_start=False, **kwargs)
535+
ax = self.new_horizontal(
536+
size, pad, pack_start=False, axes_class=axes_class, **kwargs)
553537
elif position == "bottom":
554-
ax = self.new_vertical(size, pad, pack_start=True, **kwargs)
538+
ax = self.new_vertical(
539+
size, pad, pack_start=True, axes_class=axes_class, **kwargs)
555540
elif position == "top":
556-
ax = self.new_vertical(size, pad, pack_start=False, **kwargs)
541+
ax = self.new_vertical(
542+
size, pad, pack_start=False, axes_class=axes_class, **kwargs)
557543
else:
558544
_api.check_in_list(["left", "right", "bottom", "top"],
559545
position=position)

0 commit comments

Comments
 (0)