axes_divider.py 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  1. """
  2. Helper classes to adjust the positions of multiple axes at drawing time.
  3. """
  4. import functools
  5. import numpy as np
  6. import matplotlib as mpl
  7. from matplotlib import _api
  8. from matplotlib.gridspec import SubplotSpec
  9. import matplotlib.transforms as mtransforms
  10. from . import axes_size as Size
  11. class Divider:
  12. """
  13. An Axes positioning class.
  14. The divider is initialized with lists of horizontal and vertical sizes
  15. (:mod:`mpl_toolkits.axes_grid1.axes_size`) based on which a given
  16. rectangular area will be divided.
  17. The `new_locator` method then creates a callable object
  18. that can be used as the *axes_locator* of the axes.
  19. """
  20. def __init__(self, fig, pos, horizontal, vertical,
  21. aspect=None, anchor="C"):
  22. """
  23. Parameters
  24. ----------
  25. fig : Figure
  26. pos : tuple of 4 floats
  27. Position of the rectangle that will be divided.
  28. horizontal : list of :mod:`~mpl_toolkits.axes_grid1.axes_size`
  29. Sizes for horizontal division.
  30. vertical : list of :mod:`~mpl_toolkits.axes_grid1.axes_size`
  31. Sizes for vertical division.
  32. aspect : bool, optional
  33. Whether overall rectangular area is reduced so that the relative
  34. part of the horizontal and vertical scales have the same scale.
  35. anchor : (float, float) or {'C', 'SW', 'S', 'SE', 'E', 'NE', 'N', \
  36. 'NW', 'W'}, default: 'C'
  37. Placement of the reduced rectangle, when *aspect* is True.
  38. """
  39. self._fig = fig
  40. self._pos = pos
  41. self._horizontal = horizontal
  42. self._vertical = vertical
  43. self._anchor = anchor
  44. self.set_anchor(anchor)
  45. self._aspect = aspect
  46. self._xrefindex = 0
  47. self._yrefindex = 0
  48. self._locator = None
  49. def get_horizontal_sizes(self, renderer):
  50. return np.array([s.get_size(renderer) for s in self.get_horizontal()])
  51. def get_vertical_sizes(self, renderer):
  52. return np.array([s.get_size(renderer) for s in self.get_vertical()])
  53. def set_position(self, pos):
  54. """
  55. Set the position of the rectangle.
  56. Parameters
  57. ----------
  58. pos : tuple of 4 floats
  59. position of the rectangle that will be divided
  60. """
  61. self._pos = pos
  62. def get_position(self):
  63. """Return the position of the rectangle."""
  64. return self._pos
  65. def set_anchor(self, anchor):
  66. """
  67. Parameters
  68. ----------
  69. anchor : (float, float) or {'C', 'SW', 'S', 'SE', 'E', 'NE', 'N', \
  70. 'NW', 'W'}
  71. Either an (*x*, *y*) pair of relative coordinates (0 is left or
  72. bottom, 1 is right or top), 'C' (center), or a cardinal direction
  73. ('SW', southwest, is bottom left, etc.).
  74. See Also
  75. --------
  76. .Axes.set_anchor
  77. """
  78. if isinstance(anchor, str):
  79. _api.check_in_list(mtransforms.Bbox.coefs, anchor=anchor)
  80. elif not isinstance(anchor, (tuple, list)) or len(anchor) != 2:
  81. raise TypeError("anchor must be str or 2-tuple")
  82. self._anchor = anchor
  83. def get_anchor(self):
  84. """Return the anchor."""
  85. return self._anchor
  86. def get_subplotspec(self):
  87. return None
  88. def set_horizontal(self, h):
  89. """
  90. Parameters
  91. ----------
  92. h : list of :mod:`~mpl_toolkits.axes_grid1.axes_size`
  93. sizes for horizontal division
  94. """
  95. self._horizontal = h
  96. def get_horizontal(self):
  97. """Return horizontal sizes."""
  98. return self._horizontal
  99. def set_vertical(self, v):
  100. """
  101. Parameters
  102. ----------
  103. v : list of :mod:`~mpl_toolkits.axes_grid1.axes_size`
  104. sizes for vertical division
  105. """
  106. self._vertical = v
  107. def get_vertical(self):
  108. """Return vertical sizes."""
  109. return self._vertical
  110. def set_aspect(self, aspect=False):
  111. """
  112. Parameters
  113. ----------
  114. aspect : bool
  115. """
  116. self._aspect = aspect
  117. def get_aspect(self):
  118. """Return aspect."""
  119. return self._aspect
  120. def set_locator(self, _locator):
  121. self._locator = _locator
  122. def get_locator(self):
  123. return self._locator
  124. def get_position_runtime(self, ax, renderer):
  125. if self._locator is None:
  126. return self.get_position()
  127. else:
  128. return self._locator(ax, renderer).bounds
  129. @staticmethod
  130. def _calc_k(sizes, total):
  131. # sizes is a (n, 2) array of (rel_size, abs_size); this method finds
  132. # the k factor such that sum(rel_size * k + abs_size) == total.
  133. rel_sum, abs_sum = sizes.sum(0)
  134. return (total - abs_sum) / rel_sum if rel_sum else 0
  135. @staticmethod
  136. def _calc_offsets(sizes, k):
  137. # Apply k factors to (n, 2) sizes array of (rel_size, abs_size); return
  138. # the resulting cumulative offset positions.
  139. return np.cumsum([0, *(sizes @ [k, 1])])
  140. def new_locator(self, nx, ny, nx1=None, ny1=None):
  141. """
  142. Return an axes locator callable for the specified cell.
  143. Parameters
  144. ----------
  145. nx, nx1 : int
  146. Integers specifying the column-position of the
  147. cell. When *nx1* is None, a single *nx*-th column is
  148. specified. Otherwise, location of columns spanning between *nx*
  149. to *nx1* (but excluding *nx1*-th column) is specified.
  150. ny, ny1 : int
  151. Same as *nx* and *nx1*, but for row positions.
  152. """
  153. if nx1 is None:
  154. nx1 = nx + 1
  155. if ny1 is None:
  156. ny1 = ny + 1
  157. # append_size("left") adds a new size at the beginning of the
  158. # horizontal size lists; this shift transforms e.g.
  159. # new_locator(nx=2, ...) into effectively new_locator(nx=3, ...). To
  160. # take that into account, instead of recording nx, we record
  161. # nx-self._xrefindex, where _xrefindex is shifted by 1 by each
  162. # append_size("left"), and re-add self._xrefindex back to nx in
  163. # _locate, when the actual axes position is computed. Ditto for y.
  164. xref = self._xrefindex
  165. yref = self._yrefindex
  166. locator = functools.partial(
  167. self._locate, nx - xref, ny - yref, nx1 - xref, ny1 - yref)
  168. locator.get_subplotspec = self.get_subplotspec
  169. return locator
  170. def _locate(self, nx, ny, nx1, ny1, axes, renderer):
  171. """
  172. Implementation of ``divider.new_locator().__call__``.
  173. The axes locator callable returned by ``new_locator()`` is created as
  174. a `functools.partial` of this method with *nx*, *ny*, *nx1*, and *ny1*
  175. specifying the requested cell.
  176. """
  177. nx += self._xrefindex
  178. nx1 += self._xrefindex
  179. ny += self._yrefindex
  180. ny1 += self._yrefindex
  181. fig_w, fig_h = self._fig.bbox.size / self._fig.dpi
  182. x, y, w, h = self.get_position_runtime(axes, renderer)
  183. hsizes = self.get_horizontal_sizes(renderer)
  184. vsizes = self.get_vertical_sizes(renderer)
  185. k_h = self._calc_k(hsizes, fig_w * w)
  186. k_v = self._calc_k(vsizes, fig_h * h)
  187. if self.get_aspect():
  188. k = min(k_h, k_v)
  189. ox = self._calc_offsets(hsizes, k)
  190. oy = self._calc_offsets(vsizes, k)
  191. ww = (ox[-1] - ox[0]) / fig_w
  192. hh = (oy[-1] - oy[0]) / fig_h
  193. pb = mtransforms.Bbox.from_bounds(x, y, w, h)
  194. pb1 = mtransforms.Bbox.from_bounds(x, y, ww, hh)
  195. x0, y0 = pb1.anchored(self.get_anchor(), pb).p0
  196. else:
  197. ox = self._calc_offsets(hsizes, k_h)
  198. oy = self._calc_offsets(vsizes, k_v)
  199. x0, y0 = x, y
  200. if nx1 is None:
  201. nx1 = -1
  202. if ny1 is None:
  203. ny1 = -1
  204. x1, w1 = x0 + ox[nx] / fig_w, (ox[nx1] - ox[nx]) / fig_w
  205. y1, h1 = y0 + oy[ny] / fig_h, (oy[ny1] - oy[ny]) / fig_h
  206. return mtransforms.Bbox.from_bounds(x1, y1, w1, h1)
  207. def append_size(self, position, size):
  208. _api.check_in_list(["left", "right", "bottom", "top"],
  209. position=position)
  210. if position == "left":
  211. self._horizontal.insert(0, size)
  212. self._xrefindex += 1
  213. elif position == "right":
  214. self._horizontal.append(size)
  215. elif position == "bottom":
  216. self._vertical.insert(0, size)
  217. self._yrefindex += 1
  218. else: # 'top'
  219. self._vertical.append(size)
  220. def add_auto_adjustable_area(self, use_axes, pad=0.1, adjust_dirs=None):
  221. """
  222. Add auto-adjustable padding around *use_axes* to take their decorations
  223. (title, labels, ticks, ticklabels) into account during layout.
  224. Parameters
  225. ----------
  226. use_axes : `~matplotlib.axes.Axes` or list of `~matplotlib.axes.Axes`
  227. The Axes whose decorations are taken into account.
  228. pad : float, default: 0.1
  229. Additional padding in inches.
  230. adjust_dirs : list of {"left", "right", "bottom", "top"}, optional
  231. The sides where padding is added; defaults to all four sides.
  232. """
  233. if adjust_dirs is None:
  234. adjust_dirs = ["left", "right", "bottom", "top"]
  235. for d in adjust_dirs:
  236. self.append_size(d, Size._AxesDecorationsSize(use_axes, d) + pad)
  237. class SubplotDivider(Divider):
  238. """
  239. The Divider class whose rectangle area is specified as a subplot geometry.
  240. """
  241. def __init__(self, fig, *args, horizontal=None, vertical=None,
  242. aspect=None, anchor='C'):
  243. """
  244. Parameters
  245. ----------
  246. fig : `~matplotlib.figure.Figure`
  247. *args : tuple (*nrows*, *ncols*, *index*) or int
  248. The array of subplots in the figure has dimensions ``(nrows,
  249. ncols)``, and *index* is the index of the subplot being created.
  250. *index* starts at 1 in the upper left corner and increases to the
  251. right.
  252. If *nrows*, *ncols*, and *index* are all single digit numbers, then
  253. *args* can be passed as a single 3-digit number (e.g. 234 for
  254. (2, 3, 4)).
  255. horizontal : list of :mod:`~mpl_toolkits.axes_grid1.axes_size`, optional
  256. Sizes for horizontal division.
  257. vertical : list of :mod:`~mpl_toolkits.axes_grid1.axes_size`, optional
  258. Sizes for vertical division.
  259. aspect : bool, optional
  260. Whether overall rectangular area is reduced so that the relative
  261. part of the horizontal and vertical scales have the same scale.
  262. anchor : (float, float) or {'C', 'SW', 'S', 'SE', 'E', 'NE', 'N', \
  263. 'NW', 'W'}, default: 'C'
  264. Placement of the reduced rectangle, when *aspect* is True.
  265. """
  266. self.figure = fig
  267. super().__init__(fig, [0, 0, 1, 1],
  268. horizontal=horizontal or [], vertical=vertical or [],
  269. aspect=aspect, anchor=anchor)
  270. self.set_subplotspec(SubplotSpec._from_subplot_args(fig, args))
  271. def get_position(self):
  272. """Return the bounds of the subplot box."""
  273. return self.get_subplotspec().get_position(self.figure).bounds
  274. def get_subplotspec(self):
  275. """Get the SubplotSpec instance."""
  276. return self._subplotspec
  277. def set_subplotspec(self, subplotspec):
  278. """Set the SubplotSpec instance."""
  279. self._subplotspec = subplotspec
  280. self.set_position(subplotspec.get_position(self.figure))
  281. class AxesDivider(Divider):
  282. """
  283. Divider based on the preexisting axes.
  284. """
  285. def __init__(self, axes, xref=None, yref=None):
  286. """
  287. Parameters
  288. ----------
  289. axes : :class:`~matplotlib.axes.Axes`
  290. xref
  291. yref
  292. """
  293. self._axes = axes
  294. if xref is None:
  295. self._xref = Size.AxesX(axes)
  296. else:
  297. self._xref = xref
  298. if yref is None:
  299. self._yref = Size.AxesY(axes)
  300. else:
  301. self._yref = yref
  302. super().__init__(fig=axes.get_figure(), pos=None,
  303. horizontal=[self._xref], vertical=[self._yref],
  304. aspect=None, anchor="C")
  305. def _get_new_axes(self, *, axes_class=None, **kwargs):
  306. axes = self._axes
  307. if axes_class is None:
  308. axes_class = type(axes)
  309. return axes_class(axes.get_figure(), axes.get_position(original=True),
  310. **kwargs)
  311. def new_horizontal(self, size, pad=None, pack_start=False, **kwargs):
  312. """
  313. Helper method for ``append_axes("left")`` and ``append_axes("right")``.
  314. See the documentation of `append_axes` for more details.
  315. :meta private:
  316. """
  317. if pad is None:
  318. pad = mpl.rcParams["figure.subplot.wspace"] * self._xref
  319. pos = "left" if pack_start else "right"
  320. if pad:
  321. if not isinstance(pad, Size._Base):
  322. pad = Size.from_any(pad, fraction_ref=self._xref)
  323. self.append_size(pos, pad)
  324. if not isinstance(size, Size._Base):
  325. size = Size.from_any(size, fraction_ref=self._xref)
  326. self.append_size(pos, size)
  327. locator = self.new_locator(
  328. nx=0 if pack_start else len(self._horizontal) - 1,
  329. ny=self._yrefindex)
  330. ax = self._get_new_axes(**kwargs)
  331. ax.set_axes_locator(locator)
  332. return ax
  333. def new_vertical(self, size, pad=None, pack_start=False, **kwargs):
  334. """
  335. Helper method for ``append_axes("top")`` and ``append_axes("bottom")``.
  336. See the documentation of `append_axes` for more details.
  337. :meta private:
  338. """
  339. if pad is None:
  340. pad = mpl.rcParams["figure.subplot.hspace"] * self._yref
  341. pos = "bottom" if pack_start else "top"
  342. if pad:
  343. if not isinstance(pad, Size._Base):
  344. pad = Size.from_any(pad, fraction_ref=self._yref)
  345. self.append_size(pos, pad)
  346. if not isinstance(size, Size._Base):
  347. size = Size.from_any(size, fraction_ref=self._yref)
  348. self.append_size(pos, size)
  349. locator = self.new_locator(
  350. nx=self._xrefindex,
  351. ny=0 if pack_start else len(self._vertical) - 1)
  352. ax = self._get_new_axes(**kwargs)
  353. ax.set_axes_locator(locator)
  354. return ax
  355. def append_axes(self, position, size, pad=None, *, axes_class=None,
  356. **kwargs):
  357. """
  358. Add a new axes on a given side of the main axes.
  359. Parameters
  360. ----------
  361. position : {"left", "right", "bottom", "top"}
  362. Where the new axes is positioned relative to the main axes.
  363. size : :mod:`~mpl_toolkits.axes_grid1.axes_size` or float or str
  364. The axes width or height. float or str arguments are interpreted
  365. as ``axes_size.from_any(size, AxesX(<main_axes>))`` for left or
  366. right axes, and likewise with ``AxesY`` for bottom or top axes.
  367. pad : :mod:`~mpl_toolkits.axes_grid1.axes_size` or float or str
  368. Padding between the axes. float or str arguments are interpreted
  369. as for *size*. Defaults to :rc:`figure.subplot.wspace` times the
  370. main Axes width (left or right axes) or :rc:`figure.subplot.hspace`
  371. times the main Axes height (bottom or top axes).
  372. axes_class : subclass type of `~.axes.Axes`, optional
  373. The type of the new axes. Defaults to the type of the main axes.
  374. **kwargs
  375. All extra keywords arguments are passed to the created axes.
  376. """
  377. create_axes, pack_start = _api.check_getitem({
  378. "left": (self.new_horizontal, True),
  379. "right": (self.new_horizontal, False),
  380. "bottom": (self.new_vertical, True),
  381. "top": (self.new_vertical, False),
  382. }, position=position)
  383. ax = create_axes(
  384. size, pad, pack_start=pack_start, axes_class=axes_class, **kwargs)
  385. self._fig.add_axes(ax)
  386. return ax
  387. def get_aspect(self):
  388. if self._aspect is None:
  389. aspect = self._axes.get_aspect()
  390. if aspect == "auto":
  391. return False
  392. else:
  393. return True
  394. else:
  395. return self._aspect
  396. def get_position(self):
  397. if self._pos is None:
  398. bbox = self._axes.get_position(original=True)
  399. return bbox.bounds
  400. else:
  401. return self._pos
  402. def get_anchor(self):
  403. if self._anchor is None:
  404. return self._axes.get_anchor()
  405. else:
  406. return self._anchor
  407. def get_subplotspec(self):
  408. return self._axes.get_subplotspec()
  409. # Helper for HBoxDivider/VBoxDivider.
  410. # The variable names are written for a horizontal layout, but the calculations
  411. # work identically for vertical layouts.
  412. def _locate(x, y, w, h, summed_widths, equal_heights, fig_w, fig_h, anchor):
  413. total_width = fig_w * w
  414. max_height = fig_h * h
  415. # Determine the k factors.
  416. n = len(equal_heights)
  417. eq_rels, eq_abss = equal_heights.T
  418. sm_rels, sm_abss = summed_widths.T
  419. A = np.diag([*eq_rels, 0])
  420. A[:n, -1] = -1
  421. A[-1, :-1] = sm_rels
  422. B = [*(-eq_abss), total_width - sm_abss.sum()]
  423. # A @ K = B: This finds factors {k_0, ..., k_{N-1}, H} so that
  424. # eq_rel_i * k_i + eq_abs_i = H for all i: all axes have the same height
  425. # sum(sm_rel_i * k_i + sm_abs_i) = total_width: fixed total width
  426. # (foo_rel_i * k_i + foo_abs_i will end up being the size of foo.)
  427. *karray, height = np.linalg.solve(A, B)
  428. if height > max_height: # Additionally, upper-bound the height.
  429. karray = (max_height - eq_abss) / eq_rels
  430. # Compute the offsets corresponding to these factors.
  431. ox = np.cumsum([0, *(sm_rels * karray + sm_abss)])
  432. ww = (ox[-1] - ox[0]) / fig_w
  433. h0_rel, h0_abs = equal_heights[0]
  434. hh = (karray[0]*h0_rel + h0_abs) / fig_h
  435. pb = mtransforms.Bbox.from_bounds(x, y, w, h)
  436. pb1 = mtransforms.Bbox.from_bounds(x, y, ww, hh)
  437. x0, y0 = pb1.anchored(anchor, pb).p0
  438. return x0, y0, ox, hh
  439. class HBoxDivider(SubplotDivider):
  440. """
  441. A `.SubplotDivider` for laying out axes horizontally, while ensuring that
  442. they have equal heights.
  443. Examples
  444. --------
  445. .. plot:: gallery/axes_grid1/demo_axes_hbox_divider.py
  446. """
  447. def new_locator(self, nx, nx1=None):
  448. """
  449. Create an axes locator callable for the specified cell.
  450. Parameters
  451. ----------
  452. nx, nx1 : int
  453. Integers specifying the column-position of the
  454. cell. When *nx1* is None, a single *nx*-th column is
  455. specified. Otherwise, location of columns spanning between *nx*
  456. to *nx1* (but excluding *nx1*-th column) is specified.
  457. """
  458. return super().new_locator(nx, 0, nx1, 0)
  459. def _locate(self, nx, ny, nx1, ny1, axes, renderer):
  460. # docstring inherited
  461. nx += self._xrefindex
  462. nx1 += self._xrefindex
  463. fig_w, fig_h = self._fig.bbox.size / self._fig.dpi
  464. x, y, w, h = self.get_position_runtime(axes, renderer)
  465. summed_ws = self.get_horizontal_sizes(renderer)
  466. equal_hs = self.get_vertical_sizes(renderer)
  467. x0, y0, ox, hh = _locate(
  468. x, y, w, h, summed_ws, equal_hs, fig_w, fig_h, self.get_anchor())
  469. if nx1 is None:
  470. nx1 = -1
  471. x1, w1 = x0 + ox[nx] / fig_w, (ox[nx1] - ox[nx]) / fig_w
  472. y1, h1 = y0, hh
  473. return mtransforms.Bbox.from_bounds(x1, y1, w1, h1)
  474. class VBoxDivider(SubplotDivider):
  475. """
  476. A `.SubplotDivider` for laying out axes vertically, while ensuring that
  477. they have equal widths.
  478. """
  479. def new_locator(self, ny, ny1=None):
  480. """
  481. Create an axes locator callable for the specified cell.
  482. Parameters
  483. ----------
  484. ny, ny1 : int
  485. Integers specifying the row-position of the
  486. cell. When *ny1* is None, a single *ny*-th row is
  487. specified. Otherwise, location of rows spanning between *ny*
  488. to *ny1* (but excluding *ny1*-th row) is specified.
  489. """
  490. return super().new_locator(0, ny, 0, ny1)
  491. def _locate(self, nx, ny, nx1, ny1, axes, renderer):
  492. # docstring inherited
  493. ny += self._yrefindex
  494. ny1 += self._yrefindex
  495. fig_w, fig_h = self._fig.bbox.size / self._fig.dpi
  496. x, y, w, h = self.get_position_runtime(axes, renderer)
  497. summed_hs = self.get_vertical_sizes(renderer)
  498. equal_ws = self.get_horizontal_sizes(renderer)
  499. y0, x0, oy, ww = _locate(
  500. y, x, h, w, summed_hs, equal_ws, fig_h, fig_w, self.get_anchor())
  501. if ny1 is None:
  502. ny1 = -1
  503. x1, w1 = x0, ww
  504. y1, h1 = y0 + oy[ny] / fig_h, (oy[ny1] - oy[ny]) / fig_h
  505. return mtransforms.Bbox.from_bounds(x1, y1, w1, h1)
  506. def make_axes_locatable(axes):
  507. divider = AxesDivider(axes)
  508. locator = divider.new_locator(nx=0, ny=0)
  509. axes.set_axes_locator(locator)
  510. return divider
  511. def make_axes_area_auto_adjustable(
  512. ax, use_axes=None, pad=0.1, adjust_dirs=None):
  513. """
  514. Add auto-adjustable padding around *ax* to take its decorations (title,
  515. labels, ticks, ticklabels) into account during layout, using
  516. `.Divider.add_auto_adjustable_area`.
  517. By default, padding is determined from the decorations of *ax*.
  518. Pass *use_axes* to consider the decorations of other Axes instead.
  519. """
  520. if adjust_dirs is None:
  521. adjust_dirs = ["left", "right", "bottom", "top"]
  522. divider = make_axes_locatable(ax)
  523. if use_axes is None:
  524. use_axes = ax
  525. divider.add_auto_adjustable_area(use_axes=use_axes, pad=pad,
  526. adjust_dirs=adjust_dirs)