Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 440e16b

Browse files
committed
Added axes_grid.inset_locator
svn path=/trunk/matplotlib/; revision=7056
1 parent f1c1785 commit 440e16b

18 files changed

Lines changed: 1015 additions & 276 deletions

CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
======================================================================
22

3+
2009-04-20 Worked on axes_grid documentation. Added
4+
axes_grid.inset_locator. - JJL
5+
36
2009-04-17 Initial check-in of the axes_grid toolkit. - JJL
47

58
2009-04-17 Added a support for bbox_to_anchor in
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
:mod:`mpl_toolkits.axes_grid.axes_divider`
3+
==========================================
4+
5+
.. autoclass:: mpl_toolkits.axes_grid.axes_divider.Divider
6+
:members:
7+
:undoc-members:
8+
9+
10+
.. autoclass:: mpl_toolkits.axes_grid.axes_divider.AxesLocator
11+
:members:
12+
:undoc-members:
13+
14+
.. autoclass:: mpl_toolkits.axes_grid.axes_divider.SubplotDivider
15+
:members:
16+
17+
.. autoclass:: mpl_toolkits.axes_grid.axes_divider.AxesDivider
18+
:members:
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
:mod:`mpl_toolkits.axes_grid.axes_grid`
3+
=======================================
4+
5+
.. autoclass:: mpl_toolkits.axes_grid.axes_grid.AxesGrid
6+
:members:
7+
:undoc-members:
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
:mod:`mpl_toolkits.axes_grid.axes_size`
2+
=======================================
3+
4+
.. automodule:: mpl_toolkits.axes_grid.axes_size
5+
:members: Fixed, Scaled, AxesX, AxesY, MaxWidth, MaxHeight, Fraction, Padded, from_any
6+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.. _axes_grid-api-index:
2+
3+
#######################################
4+
The Matplotlib AxesGrid Toolkit API
5+
#######################################
6+
7+
:Release: |version|
8+
:Date: |today|
9+
10+
.. toctree::
11+
12+
axes_size_api.rst
13+
axes_divider_api.rst
14+
axes_grid_api.rst

doc/mpl_toolkits/axes_grid/index.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ parameter in matplotlib adjust the position of the single axes,
1010
AxesGrid toolkit provides a framework to adjust the position of
1111
multiple axes according to their aspects.
1212

13-
.. plot:: mpl_toolkits/axes_grid/figures/demo_axes_grid.py
1413

1514

1615
Documentation
@@ -20,4 +19,4 @@ Documentation
2019
:maxdepth: 2
2120

2221
users/index.rst
23-
22+
api/index.rst

doc/mpl_toolkits/axes_grid/users/axes_divider.rst

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@ AxesDivider
44
The axes_divider module provide helper classes to adjust the axes
55
positions of set of images in the drawing time.
66

7-
* *Size* This provides a classese of units that the size of each axes
8-
will be determined. For example, you can specify a fixed size
7+
* :mod:`~mpl_toolkits.axes_grid.axes_size` provides a classese of
8+
units that the size of each axes will be determined. For example,
9+
you can specify a fixed size
910

10-
* *Divider* this is the class that is used calculates the axes
11-
position. It divides the given renctangular area into several
12-
areas. You intialize the divider by setting the horizontal and
13-
vertical list of sizes that the division will be based on. You then
14-
use the new_locator method, whose return value is a callable object
15-
that can be used to set the axes_locator of the axes.
11+
* :class:`~mpl_toolkits.axes_grid.axes_size.Divider` this is the class
12+
that is used calculates the axes position. It divides the given
13+
renctangular area into several areas. You intialize the divider by
14+
setting the horizontal and vertical list of sizes that the division
15+
will be based on. You then use the new_locator method, whose return
16+
value is a callable object that can be used to set the axes_locator
17+
of the axes.
1618

1719

1820
You first initialize the divider by specifying its grids, i.e., horiz and vert.
@@ -25,10 +27,11 @@ for example,::
2527
divider = Divider(fig, rect, horiz, vert)
2628

2729
where, rect is a bounds of the box that will be divided and h0,..h3,
28-
v0,..v2 need to be an callable object that returns a tuple of two
29-
floats. The first float is the relative size, and the second float is
30-
the absolute size. Use of the subclasses contained in the Size class
31-
is recommanded. Lets' consider a following grid.
30+
v0,..v2 need to be an instance of classes in the
31+
:mod:`~mpl_toolkits.axes_grid.axes_size`. They have *get_size* method
32+
that returns a tuple of two floats. The first float is the relative
33+
size, and the second float is the absolute size. Consider a following
34+
grid.
3235

3336
+-----+-----+-----+-----+
3437
| v0 | | | |
@@ -39,34 +42,34 @@ is recommanded. Lets' consider a following grid.
3942
+-----+-----+-----+-----+
4043

4144

42-
* h0 => 2, 0
43-
* h1 => 0, 2
44-
* h2 => 0, 3
45+
* v0 => 0, 2
46+
* v1 => 2, 0
47+
* v2 => 3, 0
4548

4649
The height of the bottom row is always 2 (axes_divider internally
4750
assumes that the unit is inch). The first and the second rows with
48-
height ration of 2:3. For example, if the total height of the grid 6,
49-
the the first and second row will each occupy 2/(2+3) and 3/(2+3) of
51+
height ratio of 2:3. For example, if the total height of the grid 6,
52+
then the first and second row will each occupy 2/(2+3) and 3/(2+3) of
5053
(6-1) inches. The widths of columns (horiz) will be similarly
5154
determined. When aspect ratio is set, the total height (or width) will
5255
be adjusted accordingly.
5356

5457

55-
The Size class is a container class that contains several sub-class
58+
The :mod:`mpl_toolkits.axes_grid.axes_size` contains several classes
5659
that can be used to set the horiz and vert. For example, for the
5760
vertical configuration above will be::
5861

59-
from Size import Fixed, Scaled
62+
from mpl_toolkits.axes_grid.axes_size import Fixed, Scaled
6063
vert = [Fixed(2), Scaled(2), Scaled(3)]
6164

62-
After you set up the divider object, you
63-
Then you create a locator instance which will be given to the axes.::
65+
After you set up the divider object, then you create a locator
66+
instance which will be given to the axes.::
6467

6568
locator = divider.new_locator(nx=0, ny=1)
6669
ax.set_axes_locator(locator)
6770

6871
The return value of the new_locator method is a instance of the
69-
AxesLocator class. It is a callable object that will return the
72+
AxesLocator class. It is a callable object that returns the
7073
location and size of the cell at the first column and the second row.
7174
You may create a locator that spans over multiple cells.::
7275

doc/mpl_toolkits/axes_grid/users/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@
1010
.. toctree::
1111

1212
overview.rst
13+
axes_divider.rst

doc/mpl_toolkits/axes_grid/users/overview.rst

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
=================
2-
AxesGrid Overview
3-
=================
1+
========
2+
Overview
3+
========
44

55
The matplotlib AxesGrid toolkit is a collection of helper classes,
66
mainly to ease displaying (multiple) images in matplotlib.
@@ -347,3 +347,44 @@ coordinate.
347347
:include-source:
348348

349349

350+
InsetLocator
351+
============
352+
353+
:mod:`mpl_toolkits.axes_grid.inset_locator` provides helper classes
354+
and functions to place your (inset) axes at the anchored position of
355+
the parent axes, similarly to AnchoredArtis.
356+
357+
Using :func:`mpl_toolkits.axes_grid.inset_locator.inset_axes`, you
358+
can have inset axes whose size is either fixed, or a fixed proportion
359+
of the parent axes. For example,::
360+
361+
inset_axes = inset_axes(parent_axes,
362+
width="30%", # width = 30% of parent_bbox
363+
height=1., # height : 1 inch
364+
loc=3)
365+
366+
creates an inset axes whose width is 30% of the parent axes and whose
367+
height is fixed at 1 inch.
368+
369+
You may creates your inset whose size is determined so that the data
370+
scale of the inset axes to be that of the parent axes multiplied by
371+
some factor. For example, ::
372+
373+
inset_axes = zoomed_inset_axes(ax,
374+
0.5, # zoom = 0.5
375+
loc=1)
376+
377+
creates an inset axes whose data scale is half of the parent axes.
378+
Here is complete examples.
379+
380+
.. plot:: mpl_toolkits/axes_grid/figures/inset_locator_demo.py
381+
382+
For example, :func:`zoomed_inset_axes` can be used when you want the
383+
inset represents the zoom-up of the small portion in the parent axes.
384+
And :mod:`~mpl_toolkits/axes_grid/inset_locator` provides a helper
385+
function :func:`mark_inset` to mark the location of the area
386+
represented by the inset axes.
387+
388+
.. plot:: mpl_toolkits/axes_grid/figures/inset_locator_demo2.py
389+
:include-source:
390+
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import matplotlib.pyplot as plt
2+
3+
from mpl_toolkits.axes_grid.inset_locator import inset_axes, zoomed_inset_axes
4+
from mpl_toolkits.axes_grid.anchored_artists import AnchoredSizeBar
5+
6+
7+
def add_sizebar(ax, size):
8+
as = AnchoredSizeBar(ax.transData,
9+
size,
10+
str(size),
11+
loc=8,
12+
pad=0.1, borderpad=0.5, sep=5,
13+
frameon=False)
14+
ax.add_artist(as)
15+
16+
17+
fig = plt.figure(1, [5.5, 3])
18+
19+
# first subplot
20+
ax = fig.add_subplot(1,2,1)
21+
ax.set_aspect(1.)
22+
23+
axins = inset_axes(ax,
24+
width="30%", # width = 30% of parent_bbox
25+
height=1., # height : 1 inch
26+
loc=3)
27+
28+
plt.xticks(visible=False)
29+
plt.yticks(visible=False)
30+
31+
32+
# second subplot
33+
ax = fig.add_subplot(1,2,2)
34+
ax.set_aspect(1.)
35+
36+
axins = zoomed_inset_axes(ax, 0.5, loc=1) # zoom = 0.5
37+
38+
plt.xticks(visible=False)
39+
plt.yticks(visible=False)
40+
41+
add_sizebar(ax, 0.5)
42+
add_sizebar(axins, 0.5)
43+
44+
plt.draw()
45+
plt.show()

0 commit comments

Comments
 (0)