|
332 | 332 | units that are used to determine the size of each axes. For example,
|
333 | 333 | you can specify a fixed size.
|
334 | 334 |
|
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 |
336 | 336 | calculates the axes position. It divides the given rectangular area into
|
337 | 337 | several areas. The divider is initialized by setting the lists of horizontal
|
338 | 338 | and vertical sizes on which the division will be based. Then use
|
339 | 339 | :meth:`~mpl_toolkits.axes_grid1.axes_divider.Divider.new_locator`, which
|
340 | 340 | returns a callable object that can be used to set the axes_locator of the
|
341 | 341 | axes.
|
342 | 342 |
|
| 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): |
343 | 346 |
|
344 |
| -First, initialize the divider by specifying its grids, i.e., |
345 |
| -horizontal and vertical:: |
| 347 | +.. code-block:: none |
346 | 348 |
|
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.) |
351 | 361 |
|
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:: |
358 | 364 |
|
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)] |
366 | 367 |
|
| 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)``.) |
367 | 372 |
|
368 |
| -* v0 => 0, 2 |
369 |
| -* v1 => 2, 0 |
370 |
| -* v2 => 3, 0 |
| 373 | +We use these constraints to initialize a `.Divider` object:: |
371 | 374 |
|
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) |
379 | 379 |
|
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:: |
383 | 382 |
|
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). |
386 | 384 |
|
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:: |
389 | 386 |
|
390 |
| - locator = divider.new_locator(nx=0, ny=1) |
391 |
| - ax.set_axes_locator(locator) |
| 387 | + ax.set_axes_locator(locator) |
392 | 388 |
|
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. |
397 | 391 |
|
398 |
| - locator = divider.new_locator(nx=0, nx=2, ny=1) |
| 392 | +Locators that spans over multiple cells can be created with, e.g.:: |
399 | 393 |
|
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) |
403 | 396 |
|
404 | 397 | See the example,
|
405 | 398 |
|
|
408 | 401 | :align: center
|
409 | 402 | :scale: 50
|
410 | 403 |
|
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 |
414 | 405 | data limits (AxesX and AxesY).
|
415 | 406 |
|
416 | 407 | .. figure:: ../../gallery/axes_grid1/images/sphx_glr_simple_axes_divider3_001.png
|
417 | 408 | :target: ../../gallery/axes_grid1/simple_axes_divider3.html
|
418 | 409 | :align: center
|
419 | 410 | :scale: 50
|
420 |
| -
|
421 |
| - Simple Axes Divider3 |
422 | 411 | """
|
0 commit comments