8000 Reword axes_divider tutorial. · matplotlib/matplotlib@9f15e85 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9f15e85

Browse files
committed
Reword axes_divider tutorial.
Hopefully this is a bit easier to follow...
1 parent a00fdf1 commit 9f15e85

File tree

1 file changed

+41
-52
lines changed

1 file changed

+41
-52
lines changed

tutorials/toolkits/axes_grid.py

Lines changed: 41 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -332,74 +332,67 @@
332332
units that are used to determine the size of each axes. For example,
333333
you can specify a fixed size.
334334
335-
* :class:`~mpl_toolkits.axes_grid1.axes_divider.Divider` is the class that
335+
* `~mpl_toolkits.axes_grid1.axes_divider.Divider` is the class that
336336
calculates the axes position. It divides the given rectangular area into
337337
several areas. The divider is initialized by setting the lists of horizontal
338338
and vertical sizes on which the division will be based. Then use
339339
:meth:`~mpl_toolkits.axes_grid1.axes_divider.Divider.new_locator`, which
340340
returns a callable object that can be used to set the axes_locator of the
341341
axes.
342342
343+
Here, we demonstrate how to achieve the following layout: we want to position
344+
axes in a 3x4 grid (note that `.Divider` makes row indices start from the
345+
*bottom*\(!) of the grid):
343346
344-
First, initialize the divider by specifying its grids, i.e.,
345-
horizontal and vertical::
347+
.. code-block:: none
346348
347-
rect = [0.2, 0.2, 0.6, 0.6]
348-
horiz = [h0, h1, h2, h3]
349-
vert = [v0, v1, v2]
350-
divider = Divider(fig, rect, horiz, vert)
349+
+--------+--------+--------+--------+
350+
| (2, 0) | (2, 1) | (2, 2) | (2, 3) |
351+
+--------+--------+--------+--------+
352+
| (1, 0) | (1, 1) | (1, 2) | (1, 3) |
353+
+--------+--------+--------+--------+
354+
| (0, 0) | (0, 1) | (0, 2) | (0, 3) |
355+
+--------+--------+--------+--------+
356+
357+
such that the bottom row has a fixed height of 2 (inches) and the top two rows
358+
have a height ratio of 2 (middle) to 3 (top). (For example, if the grid has
359+
a size of 7 inches, the bottom row will be 2 inches, the middle row also 2
360+
inches, and the top row 3 inches.)
351361
352-
where rect is a bounds of the box that will be divided and h0, ..., h3,
353-
v0, ..., v2 need to be instance of classes in the
354-
:mod:`~mpl_toolkits.axes_grid1.axes_size`. They have *get_size* method
355-
that returns a tuple of two floats. The first float is the relative
356-
size, and the second float is the absolute size. Consider a following
357-
grid.
362+
These constraints are specified using classes from the
363+
:mod:`~mpl_toolkits.axes_grid1.axes_size` module, namely::
358364
359-
+------+-----+-----+-----+
360-
| v0 | | | |
361-
+------+-----+-----+-----+
362-
| v1 | | | |
363-
+------+-----+-----+-----+
364-
|h0, v2| h1 | h2 | h3 |
365-
+------+-----+-----+-----+
365+
from mpl_toolkits.axes_grid1.axes_size import Fixed, Scaled
366+
vert = [Fixed(2), Scaled(2), Scaled(3)]
366367
368+
(More generally, :mod:`~mpl_toolkits.axes_grid1.axes_size` classes define a
369+
``get_size(renderer)`` method that returns a pair of floats -- a relative size,
370+
and an absolute size. ``Fixed(2).get_size(renderer)`` returns ``(0, 2)``;
371+
``Scaled(2).get_size(renderer)`` returns ``(2, 0)``.)
367372
368-
* v0 => 0, 2
369-
* v1 => 2, 0
370-
* v2 => 3, 0
373+
We use these constraints to initialize a `.Divider` object::
371374
372-
The height of the bottom row is always 2 (axes_divider internally
373-
assumes that the unit is inches). The first and the second rows have a
374-
height ratio of 2:3. For example, if the total height of the grid is 6,
375-
then the first and second row will each occupy 2/(2+3) and 3/(2+3) of
376-
(6-1) inches. The widths of the horizontal columns will be similarly
377-
determined. When the aspect ratio is set, the total height (or width) will
378-
be adjusted accordingly.
375+
rect = [0.2, 0.2, 0.6, 0.6] # Position of the grid in the figure.
376+
vert = [Fixed(2), Scaled(2), Scaled(3)] # As above.
377+
horiz = [...] # Some other horizontal constraints.
378+
divider = Divider(fig, rect, horiz, vert)
379379
380-
The :mod:`mpl_toolkits.axes_grid1.axes_size` contains several classes
381-
that can be used to set the horizontal and vertical configurations. For
382-
example, for vertical configuration one could use::
380+
then use `.Divider.new_locator` to create an `.AxesLocator` instance for a
381+
given grid entry::
383382
384-
from mpl_toolkits.axes_grid1.axes_size import Fixed, Scaled
385-
vert = [Fixed(2), Scaled(2), Scaled(3)]
383+
locator = divider.new_locator(nx=0, ny=1) # Grid entry (1, 0).
386384
387-
After you set up the divider object, then you create a locator
388-
instance that will be given to the axes object.::
385+
and make it responsible for locating the axes::
389386
390-
locator = divider.new_locator(nx=0, ny=1)
391-
ax.set_axes_locator(locator)
387+
ax.set_axes_locator(locator)
392388
393-
The return value of the new_locator method is an instance of the
394-
AxesLocator class. It is a callable object that returns the
395-
location and size of the cell at the first column and the second row.
396-
You may create a locator that spans over multiple cells.::
389+
The `.AxesLocator` is a callable object that returns the location and size of
390+
the cell at the first column and the second row.
397391
398-
locator = divider.new_locator(nx=0, nx=2, ny=1)
392+
Locators that spans over multiple cells can be created with, e.g.::
399393
400-
The above locator, when called, will return the position and size of
401-
the cells spanning the first and second column and the first row. In
402-
this example, it will return [0:2, 1].
394+
# Columns #0 and #1 ("0-2 range"), row #1.
395+
locator = divider.new_locator(nx=0, nx1=2, ny=1)
403396
404397
See the example,
405398
@@ -408,15 +401,11 @@
408401
:align: center
409402
:scale: 50
410403
411-
Simple Axes Divider2
412-
413-
You can adjust the size of each axes according to its x or y
404+
You can also adjust the size of each axes according to its x or y
414405
data limits (AxesX and AxesY).
415406
416407
.. figure:: ../../gallery/axes_grid1/images/sphx_glr_simple_axes_divider3_001.png
417408
:target: ../../gallery/axes_grid1/simple_axes_divider3.html
418409
:align: center
419410
:scale: 50
420-
421-
Simple Axes Divider3
422411
"""

0 commit comments

Comments
 (0)
0