Skip to content

Commit 448e3f0

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 75d2b1c commit 448e3f0

File tree

3 files changed

+40
-54
lines changed

3 files changed

+40
-54
lines changed

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
@@ -42,7 +42,7 @@
4242
ax1 = plt.axes([0, 0, 1, 1])
4343
divider = make_axes_locatable(ax1)
4444

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

lib/mpl_toolkits/axes_grid1/axes_divider.py

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

423423
def new_horizontal(self, size, pad=None, pack_start=False, **kwargs):
424424
"""
425-
Add a new axes on the right (or left) side of the main axes.
425+
Helper method for ``append_axes("left")`` and ``append_axes("right")``.
426426
427-
Parameters
428-
----------
429-
size : :mod:`~mpl_toolkits.axes_grid1.axes_size` or float or str
430-
The axes width. float or str arguments are interpreted as
431-
``axes_size.from_any(size, AxesX(<main_axes>))``.
432-
pad : :mod:`~mpl_toolkits.axes_grid1.axes_size` or float or str
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.
436-
pack_start : bool
437-
If False, the new axes is appended at the end
438-
of the list, i.e., it became the right-most axes. If True, it is
439-
inserted at the start of the list, and becomes the left-most axes.
440-
**kwargs
441-
All extra keywords arguments are passed to the created axes.
442-
If *axes_class* is given, the new axes will be created as an
443-
instance of the given class. Otherwise, the same class of the
444-
main axes will be used.
427+
See the documentation of `append_axes` for more details.
428+
429+
:meta private:
445430
"""
446431
if pad is None:
447432
pad = mpl.rcParams["figure.subplot.wspace"] * self._xref
@@ -469,26 +454,11 @@ def new_horizontal(self, size, pad=None, pack_start=False, **kwargs):
469454

470455
def new_vertical(self, size, pad=None, pack_start=False, **kwargs):
471456
"""
472-
Add a new axes on the top (or bottom) side of the main axes.
457+
Helper method for ``append_axes("top")`` and ``append_axes("bottom")``.
473458
474-
Parameters
475-
----------
476-
size : :mod:`~mpl_toolkits.axes_grid1.axes_size` or float or str
477-
The axes height. float or str arguments are interpreted as
478-
``axes_size.from_any(size, AxesY(<main_axes>))``.
479-
pad : :mod:`~mpl_toolkits.axes_grid1.axes_size` or float or str
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.
483-
pack_start : bool
484-
If False, the new axes is appended at the end
485-
of the list, i.e., it became the right-most axes. If True, it is
486-
inserted at the start of the list, and becomes the left-most axes.
487-
**kwargs
488-
All extra keywords arguments are passed to the created axes.
489-
If *axes_class* is given, the new axes will be created as an
490-
instance of the given class. Otherwise, the same class of the
491-
main axes will be used.
459+
See the documentation of `append_axes` for more details.
460+
461+
:meta private:
492462
"""
493463
if pad is None:
494464
pad = mpl.rcParams["figure.subplot.hspace"] * self._yref
@@ -509,31 +479,47 @@ def new_vertical(self, size, pad=None, pack_start=False, **kwargs):
509479
else:
510480
self._vertical.append(size)
511481
locator = self.new_locator(
512-
nx=self._xrefindex, ny=len(self._vertical)-1)
482+
nx=self._xrefindex, ny=len(self._vertical) - 1)
513483
ax = self._get_new_axes(**kwargs)
514484
ax.set_axes_locator(locator)
515485
return ax
516486

517487
@_api.delete_parameter("3.5", "add_to_figure", alternative="ax.remove()")
518-
def append_axes(self, position, size, pad=None, add_to_figure=True,
519-
**kwargs):
488+
def append_axes(self, position, size, pad=None, add_to_figure=True, *,
489+
axes_class=None, **kwargs):
520490
"""
521-
Create an axes at the given *position* with the same height
522-
(or width) of the main axes.
491+
Add a new axes on a given side of the main axes.
523492
524-
*position*
525-
["left"|"right"|"bottom"|"top"]
526-
527-
*size* and *pad* should be axes_grid.axes_size compatible.
493+
Parameters
494+
----------
495+
position : {"left", "right", "bottom", "top"}
496+
Where the new axes is positioned relative to the main axes.
497+
size : :mod:`~mpl_toolkits.axes_grid1.axes_size` or float or str
498+
The axes width. float or str arguments are interpreted as
499+
``axes_size.from_any(size, AxesX(<main_axes>))`` for left or right
500+
axes, and likewise with ``AxesY`` for bottom or top axes.
501+
pad : :mod:`~mpl_toolkits.axes_grid1.axes_size` or float or str
502+
Padding between the axes. float or str arguments are interpreted
503+
as for *size*. Defaults to :rc:`figure.subplot.wspace` times the
504+
main axes width (left or right axes) or :rc:`figure.subplot.hspace`
505+
times the main axes height (bottom or top axes).
506+
axes_class : subclass type of `~.axes.Axes`, optional
507+
The type of the new axes. Defaults to the type of the main axes.
508+
**kwargs
509+
All extra keywords arguments are passed to the created axes.
528510
"""
529511
if position == "left":
530-
ax = self.new_horizontal(size, pad, pack_start=True, **kwargs)
512+
ax = self.new_horizontal(
513+
size, pad, pack_start=True, axes_class=axes_class, **kwargs)
531514
elif position == "right":
532-
ax = self.new_horizontal(size, pad, pack_start=False, **kwargs)
515+
ax = self.new_horizontal(
516+
size, pad, pack_start=False, axes_class=axes_class, **kwargs)
533517
elif position == "bottom":
534-
ax = self.new_vertical(size, pad, pack_start=True, **kwargs)
518+
ax = self.new_vertical(
519+
size, pad, pack_start=True, axes_class=axes_class, **kwargs)
535520
elif position == "top":
536-
ax = self.new_vertical(size, pad, pack_start=False, **kwargs)
521+
ax = self.new_vertical(
522+
size, pad, pack_start=False, axes_class=axes_class, **kwargs)
537523
else:
538524
_api.check_in_list(["left", "right", "bottom", "top"],
539525
position=position)

0 commit comments

Comments
 (0)