|
328 | 328 | units that are used to determine the size of each axes. For example, |
329 | 329 | you can specify a fixed size. |
330 | 330 |
|
331 | | -* :class:`~mpl_toolkits.axes_grid1.axes_divider.Divider` is the class that |
| 331 | +* `~mpl_toolkits.axes_grid1.axes_divider.Divider` is the class that |
332 | 332 | calculates the axes position. It divides the given rectangular area into |
333 | 333 | several areas. The divider is initialized by setting the lists of horizontal |
334 | 334 | and vertical sizes on which the division will be based. Then use |
335 | 335 | :meth:`~mpl_toolkits.axes_grid1.axes_divider.Divider.new_locator`, which |
336 | 336 | returns a callable object that can be used to set the axes_locator of the |
337 | 337 | axes. |
338 | 338 |
|
| 339 | +Here, we demonstrate how to achieve the following layout: we want to position |
| 340 | +axes in a 3x4 grid (note that `.Divider` makes row indices start from the |
| 341 | +*bottom*\(!) of the grid): |
339 | 342 |
|
340 | | -First, initialize the divider by specifying its grids, i.e., |
341 | | -horizontal and vertical:: |
| 343 | +.. code-block:: none |
342 | 344 |
|
343 | | - rect = [0.2, 0.2, 0.6, 0.6] |
344 | | - horiz = [h0, h1, h2, h3] |
345 | | - vert = [v0, v1, v2] |
346 | | - divider = Divider(fig, rect, horiz, vert) |
| 345 | + +--------+--------+--------+--------+ |
| 346 | + | (2, 0) | (2, 1) | (2, 2) | (2, 3) | |
| 347 | + +--------+--------+--------+--------+ |
| 348 | + | (1, 0) | (1, 1) | (1, 2) | (1, 3) | |
| 349 | + +--------+--------+--------+--------+ |
| 350 | + | (0, 0) | (0, 1) | (0, 2) | (0, 3) | |
| 351 | + +--------+--------+--------+--------+ |
| 352 | +
|
| 353 | +such that the bottom row has a fixed height of 2 (inches) and the top two rows |
| 354 | +have a height ratio of 2 (middle) to 3 (top). (For example, if the grid has |
| 355 | +a size of 7 inches, the bottom row will be 2 inches, the middle row also 2 |
| 356 | +inches, and the top row 3 inches.) |
347 | 357 |
|
348 | | -where rect is a bounds of the box that will be divided and h0, ..., h3, |
349 | | -v0, ..., v2 need to be instance of classes in the |
350 | | -:mod:`~mpl_toolkits.axes_grid1.axes_size`. They have *get_size* method |
351 | | -that returns a tuple of two floats. The first float is the relative |
352 | | -size, and the second float is the absolute size. Consider a following |
353 | | -grid. |
| 358 | +These constraints are specified using classes from the |
| 359 | +:mod:`~mpl_toolkits.axes_grid1.axes_size` module, namely:: |
354 | 360 |
|
355 | | -+------+-----+-----+-----+ |
356 | | -| v0 | | | | |
357 | | -+------+-----+-----+-----+ |
358 | | -| v1 | | | | |
359 | | -+------+-----+-----+-----+ |
360 | | -|h0, v2| h1 | h2 | h3 | |
361 | | -+------+-----+-----+-----+ |
| 361 | + from mpl_toolkits.axes_grid1.axes_size import Fixed, Scaled |
| 362 | + vert = [Fixed(2), Scaled(2), Scaled(3)] |
362 | 363 |
|
| 364 | +(More generally, :mod:`~mpl_toolkits.axes_grid1.axes_size` classes define a |
| 365 | +``get_size(renderer)`` method that returns a pair of floats -- a relative size, |
| 366 | +and an absolute size. ``Fixed(2).get_size(renderer)`` returns ``(0, 2)``; |
| 367 | +``Scaled(2).get_size(renderer)`` returns ``(2, 0)``.) |
363 | 368 |
|
364 | | -* v0 => 0, 2 |
365 | | -* v1 => 2, 0 |
366 | | -* v2 => 3, 0 |
| 369 | +We use these constraints to initialize a `.Divider` object:: |
367 | 370 |
|
368 | | -The height of the bottom row is always 2 (axes_divider internally |
369 | | -assumes that the unit is inches). The first and the second rows have a |
370 | | -height ratio of 2:3. For example, if the total height of the grid is 6, |
371 | | -then the first and second row will each occupy 2/(2+3) and 3/(2+3) of |
372 | | -(6-1) inches. The widths of the horizontal columns will be similarly |
373 | | -determined. When the aspect ratio is set, the total height (or width) will |
374 | | -be adjusted accordingly. |
| 371 | + rect = [0.2, 0.2, 0.6, 0.6] # Position of the grid in the figure. |
| 372 | + vert = [Fixed(2), Scaled(2), Scaled(3)] # As above. |
| 373 | + horiz = [...] # Some other horizontal constraints. |
| 374 | + divider = Divider(fig, rect, horiz, vert) |
375 | 375 |
|
376 | | -The :mod:`mpl_toolkits.axes_grid1.axes_size` contains several classes |
377 | | -that can be used to set the horizontal and vertical configurations. For |
378 | | -example, for vertical configuration one could use:: |
| 376 | +then use `.Divider.new_locator` to create an `.AxesLocator` instance for a |
| 377 | +given grid entry:: |
379 | 378 |
|
380 | | - from mpl_toolkits.axes_grid1.axes_size import Fixed, Scaled |
381 | | - vert = [Fixed(2), Scaled(2), Scaled(3)] |
| 379 | + locator = divider.new_locator(nx=0, ny=1) # Grid entry (1, 0). |
382 | 380 |
|
383 | | -After you set up the divider object, then you create a locator |
384 | | -instance that will be given to the axes object.:: |
| 381 | +and make it responsible for locating the axes:: |
385 | 382 |
|
386 | | - locator = divider.new_locator(nx=0, ny=1) |
387 | | - ax.set_axes_locator(locator) |
| 383 | + ax.set_axes_locator(locator) |
388 | 384 |
|
389 | | -The return value of the new_locator method is an instance of the |
390 | | -AxesLocator class. It is a callable object that returns the |
391 | | -location and size of the cell at the first column and the second row. |
392 | | -You may create a locator that spans over multiple cells.:: |
| 385 | +The `.AxesLocator` is a callable object that returns the location and size of |
| 386 | +the cell at the first column and the second row. |
393 | 387 |
|
394 | | - locator = divider.new_locator(nx=0, nx=2, ny=1) |
| 388 | +Locators that spans over multiple cells can be created with, e.g.:: |
395 | 389 |
|
396 | | -The above locator, when called, will return the position and size of |
397 | | -the cells spanning the first and second column and the first row. In |
398 | | -this example, it will return [0:2, 1]. |
| 390 | + # Columns #0 and #1 ("0-2 range"), row #1. |
| 391 | + locator = divider.new_locator(nx=0, nx1=2, ny=1) |
399 | 392 |
|
400 | 393 | See the example, |
401 | 394 |
|
|
404 | 397 | :align: center |
405 | 398 | :scale: 50 |
406 | 399 |
|
407 | | - Simple Axes Divider2 |
408 | | -
|
409 | | -You can adjust the size of each axes according to its x or y |
| 400 | +You can also adjust the size of each axes according to its x or y |
410 | 401 | data limits (AxesX and AxesY). |
411 | 402 |
|
412 | 403 | .. figure:: ../../gallery/axes_grid1/images/sphx_glr_simple_axes_divider3_001.png |
413 | 404 | :target: ../../gallery/axes_grid1/simple_axes_divider3.html |
414 | 405 | :align: center |
415 | 406 | :scale: 50 |
416 | | -
|
417 | | - Simple Axes Divider3 |
418 | 407 | """ |
0 commit comments