|
1 | 1 | r"""
|
2 |
| -============================== |
3 |
| -Overview of axes_grid1 toolkit |
4 |
| -============================== |
5 |
| -
|
6 |
| -Controlling the layout of plots with the |
7 |
| -:mod:`mpl_toolkits.axes_grid1` toolkit. |
8 |
| -
|
9 | 2 | .. _axes_grid1_users-guide-index:
|
10 | 3 |
|
| 4 | +========================================== |
| 5 | +Overview of :mod:`mpl_toolkits.axes_grid1` |
| 6 | +========================================== |
11 | 7 |
|
12 |
| -What is axes_grid1 toolkit? |
13 |
| -=========================== |
| 8 | +:mod:`.axes_grid1` provides the following features: |
14 | 9 |
|
15 |
| -:mod:`mpl_toolkits.axes_grid1` is a collection of helper classes to ease |
16 |
| -displaying (multiple) images with matplotlib. In matplotlib, the axes location |
17 |
| -(and size) is specified in the normalized figure coordinates, which |
18 |
| -may not be ideal for displaying images that needs to have a given |
19 |
| -aspect ratio. For example, it helps if you have a colorbar whose |
20 |
| -height always matches that of the image. `ImageGrid`_, `RGB Axes`_ and |
21 |
| -`AxesDivider`_ are helper classes that deal with adjusting the |
22 |
| -location of (multiple) Axes. They provides a framework to adjust the |
23 |
| -position of multiple axes at the drawing time. `ParasiteAxes`_ |
24 |
| -provides twinx(or twiny)-like features so that you can plot different |
25 |
| -data (e.g., different y-scale) in a same Axes. `AnchoredArtists`_ |
26 |
| -includes custom artists which are placed at some anchored position, |
27 |
| -like the legend. |
| 10 | +- Helper classes (ImageGrid_, RGBAxes_, AxesDivider_) to ease the layout of |
| 11 | + axes displaying images with a fixed aspect ratio while satisfying additional |
| 12 | + constraints (matching the heights of a colorbar and an image, or fixing the |
| 13 | + padding between images); |
| 14 | +- ParasiteAxes_ (twinx/twiny-like features so that you can plot different data |
| 15 | + (e.g., different y-scale) in a same Axes); |
| 16 | +- AnchoredArtists_ (custom artists which are placed at an anchored position, |
| 17 | + similarly to legends). |
28 | 18 |
|
29 | 19 | .. figure:: ../../gallery/axes_grid1/images/sphx_glr_demo_axes_grid_001.png
|
30 | 20 | :target: ../../gallery/axes_grid1/demo_axes_grid.html
|
31 | 21 | :align: center
|
32 | 22 | :scale: 50
|
33 | 23 |
|
34 |
| - Demo Axes Grid |
35 |
| -
|
36 |
| -
|
37 | 24 | axes_grid1
|
38 | 25 | ==========
|
39 | 26 |
|
40 | 27 | ImageGrid
|
41 | 28 | ---------
|
42 | 29 |
|
43 |
| -A grid of Axes. |
44 |
| -
|
45 |
| -In Matplotlib, the axes location (and size) is specified in normalized |
46 |
| -figure coordinates. This may not be ideal for images that needs to be |
47 |
| -displayed with a given aspect ratio; for example, it is difficult to |
48 |
| -display multiple images of a same size with some fixed padding between |
49 |
| -them. `~.axes_grid1.axes_grid.ImageGrid` can be used in such a case; see its |
50 |
| -docs for a detailed list of the parameters it accepts. |
| 30 | +In Matplotlib, axes location and size are usually specified in normalized |
| 31 | +figure coordinates (0 = bottom left, 1 = top right), which makes |
| 32 | +it difficult to achieve a fixed (absolute) padding between images. |
| 33 | +`~.axes_grid1.axes_grid.ImageGrid` can be used to achieve such a padding; see |
| 34 | +its docs for detailed API information. |
51 | 35 |
|
52 | 36 | .. figure:: ../../gallery/axes_grid1/images/sphx_glr_simple_axesgrid_001.png
|
53 | 37 | :target: ../../gallery/axes_grid1/simple_axesgrid.html
|
54 | 38 | :align: center
|
55 | 39 | :scale: 50
|
56 | 40 |
|
57 |
| - Simple Axesgrid |
58 |
| -
|
59 | 41 | * The position of each axes is determined at the drawing time (see
|
60 |
| - `AxesDivider`_), so that the size of the entire grid fits in the |
| 42 | + AxesDivider_), so that the size of the entire grid fits in the |
61 | 43 | given rectangle (like the aspect of axes). Note that in this example,
|
62 | 44 | the paddings between axes are fixed even if you changes the figure
|
63 | 45 | size.
|
64 | 46 |
|
65 |
| -* axes in the same column has a same axes width (in figure |
66 |
| - coordinate), and similarly, axes in the same row has a same |
67 |
| - height. The widths (height) of the axes in the same row (column) are |
68 |
| - scaled according to their view limits (xlim or ylim). |
| 47 | +* Axes in the same column share their x-axis, and axes in the same row share |
| 48 | + their y-axis (in the sense of `~.Axes.sharex`, `~.Axes.sharey`). |
| 49 | + Additionally, Axes in the same column all have the same width, and axes in |
| 50 | + the same row all have the same height. These widths and heights are scaled |
| 51 | + in proportion to the axes' view limits (xlim or ylim). |
69 | 52 |
|
70 | 53 | .. figure:: ../../gallery/axes_grid1/images/sphx_glr_simple_axesgrid2_001.png
|
71 | 54 | :target: ../../gallery/axes_grid1/simple_axesgrid2.html
|
72 | 55 | :align: center
|
73 | 56 | :scale: 50
|
74 | 57 |
|
75 |
| - Simple Axes Grid |
76 |
| -
|
77 |
| -* xaxis are shared among axes in a same column. Similarly, yaxis are |
78 |
| - shared among axes in a same row. Therefore, changing axis properties |
79 |
| - (view limits, tick location, etc. either by plot commands or using |
80 |
| - your mouse in interactive backends) of one axes will affect all |
81 |
| - other shared axes. |
82 |
| -
|
83 | 58 | The examples below show what you can do with ImageGrid.
|
84 | 59 |
|
85 | 60 | .. figure:: ../../gallery/axes_grid1/images/sphx_glr_demo_axes_grid_001.png
|
86 | 61 | :target: ../../gallery/axes_grid1/demo_axes_grid.html
|
87 | 62 | :align: center
|
88 | 63 | :scale: 50
|
89 | 64 |
|
90 |
| - Demo Axes Grid |
91 |
| -
|
92 |
| -
|
93 | 65 | AxesDivider Class
|
94 | 66 | -----------------
|
95 | 67 |
|
96 |
| -Behind the scene, the ImageGrid class and the RGBAxes class utilize the |
97 |
| -`~.axes_grid1.axes_divider.AxesDivider` class, whose role is to calculate the |
98 |
| -location of the axes at drawing time. Direct use of the |
99 |
| -AxesDivider class will not be necessary for most users. The |
100 |
| -axes_divider module provides a helper function |
101 |
| -`~.axes_grid1.axes_divider.make_axes_locatable`, which can be useful. |
102 |
| -It takes a existing axes instance and create a divider for it. :: |
| 68 | +Behind the scenes, ImageGrid (and RGBAxes, described below) rely on |
| 69 | +`~.axes_grid1.axes_divider.AxesDivider`, whose role is to calculate the |
| 70 | +location of the axes at drawing time. |
| 71 | +
|
| 72 | +Users typically do not need to directly instantiate dividers |
| 73 | +by calling `~.axes_grid1.axes_divider.AxesDivider`; instead, |
| 74 | +`~.axes_grid1.axes_divider.make_axes_locatable` can be used to create a divider |
| 75 | +for an axes:: |
103 | 76 |
|
104 | 77 | ax = subplot(1, 1, 1)
|
105 | 78 | divider = make_axes_locatable(ax)
|
106 | 79 |
|
107 |
| -*make_axes_locatable* returns an instance of the |
108 |
| -`~.axes_grid1.axes_divider.AxesDivider` class. It provides an |
109 |
| -`~.AxesDivider.append_axes` method that |
110 |
| -creates a new axes on the given side of ("top", "right", "bottom" and |
111 |
| -"left") of the original axes. |
112 |
| -
|
| 80 | +`.AxesDivider.append_axes` can then be used to create a new axes on a given |
| 81 | +side ("left", "right", "top", "bottom") of the original axes. |
113 | 82 |
|
114 | 83 | colorbar whose height (or width) in sync with the master axes
|
115 | 84 | -------------------------------------------------------------
|
|
119 | 88 | :align: center
|
120 | 89 | :scale: 50
|
121 | 90 |
|
122 |
| - Simple Colorbar |
123 |
| -
|
124 |
| -
|
125 | 91 | scatter_hist.py with AxesDivider
|
126 | 92 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
127 | 93 |
|
|
150 | 116 | :align: center
|
151 | 117 | :scale: 50
|
152 | 118 |
|
153 |
| - Scatter Hist |
154 |
| -
|
155 | 119 | The :doc:`/gallery/axes_grid1/scatter_hist_locatable_axes` using the
|
156 |
| -AxesDivider has some advantage over the |
| 120 | +AxesDivider has some advantages over the |
157 | 121 | original :doc:`/gallery/lines_bars_and_markers/scatter_hist` in Matplotlib.
|
158 | 122 | For example, you can set the aspect ratio of the scatter plot, even with the
|
159 | 123 | x-axis or y-axis is shared accordingly.
|
160 | 124 |
|
161 |
| -
|
162 | 125 | ParasiteAxes
|
163 | 126 | ------------
|
164 | 127 |
|
|
181 | 144 | parasite axes. To create a host axes, you may use *host_subplot* or
|
182 | 145
EF56
| *host_axes* command.
|
183 | 146 |
|
184 |
| -
|
185 | 147 | Example 1. twinx
|
186 | 148 | ~~~~~~~~~~~~~~~~
|
187 | 149 |
|
|
190 | 152 | :align: center
|
191 | 153 | :scale: 50
|
192 | 154 |
|
193 |
| - Parasite Simple |
194 |
| -
|
195 |
| -
|
196 | 155 | Example 2. twin
|
197 | 156 | ~~~~~~~~~~~~~~~
|
198 | 157 |
|
|
206 | 165 | ax2.set_xticklabels(["0", r"$\frac{1}{2}\pi$",
|
207 | 166 | r"$\pi$", r"$\frac{3}{2}\pi$", r"$2\pi$"])
|
208 | 167 |
|
209 |
| -
|
210 | 168 | .. figure:: ../../gallery/axes_grid1/images/sphx_glr_simple_axisline4_001.png
|
211 | 169 | :target: ../../gallery/axes_grid1/simple_axisline4.html
|
212 | 170 | :align: center
|
213 | 171 | :scale: 50
|
214 | 172 |
|
215 |
| - Simple Axisline4 |
216 |
| -
|
217 | 173 | A more sophisticated example using twin. Note that if you change the
|
218 | 174 | x-limit in the host axes, the x-limit of the parasite axes will change
|
219 | 175 | accordingly.
|
220 | 176 |
|
221 |
| -
|
222 | 177 | .. figure:: ../../gallery/axes_grid1/images/sphx_glr_parasite_simple2_001.png
|
223 | 178 | :target: ../../gallery/axes_grid1/parasite_simple2.html
|
224 | 179 | :align: center
|
225 | 180 | :scale: 50
|
226 | 181 |
|
227 |
| - Parasite Simple2 |
228 |
| -
|
229 |
| -
|
230 | 182 | AnchoredArtists
|
231 | 183 | ---------------
|
232 | 184 |
|
233 |
| -It's a collection of artists whose location is anchored to the (axes) |
234 |
| -bbox, like the legend. It is derived from *OffsetBox* in Matplotlib, and |
235 |
| -artist need to be drawn in the canvas coordinate. But, there is a |
236 |
| -limited support for an arbitrary transform. For example, the ellipse |
237 |
| -in the example below will have width and height in the data |
238 |
| -coordinate. |
| 185 | +:mod:`.axes_grid1.anchored_artists` is a collection of artists whose location |
<
F438
tr class="diff-line-row">
| 186 | +is anchored to the (axes) bbox, similarly to legends. These artists derive |
| 187 | +from `.offsetbox.OffsetBox`, and the artist need to be drawn in canvas |
| 188 | +coordinates. There is limited support for arbitrary transforms. For example, |
| 189 | +the ellipse in the example below will have width and height in data coordinate. |
239 | 190 |
|
240 | 191 | .. figure:: ../../gallery/axes_grid1/images/sphx_glr_simple_anchored_artists_001.png
|
241 | 192 | :target: ../../gallery/axes_grid1/simple_anchored_artists.html
|
242 | 193 | :align: center
|
243 | 194 | :scale: 50
|
244 | 195 |
|
245 |
| - Simple Anchored Artists |
246 |
| -
|
247 |
| -
|
248 | 196 | InsetLocator
|
249 | 197 | ------------
|
250 | 198 |
|
251 |
| -:mod:`mpl_toolkits.axes_grid1.inset_locator` provides helper classes |
252 |
| -and functions to place your (inset) axes at the anchored position of |
253 |
| -the parent axes, similarly to AnchoredArtist. |
| 199 | +.. seealso:: |
| 200 | + `.Axes.inset_axes` and `.Axes.indicate_inset_zoom` in the main library. |
254 | 201 |
|
255 |
| -Using :func:`mpl_toolkits.axes_grid1.inset_locator.inset_axes`, you |
256 |
| -can have inset axes whose size is either fixed, or a fixed proportion |
257 |
| -of the parent axes:: |
| 202 | +:mod:`.axes_grid1.inset_locator` provides helper classes and functions to |
| 203 | +place inset axes at an anchored position of the parent axes, similarly to |
| 204 | +AnchoredArtist. |
| 205 | +
|
| 206 | +`.inset_locator.inset_axes` creates an inset axes whose size is either fixed, |
| 207 | +or a fixed proportion of the parent axes:: |
258 | 208 |
|
259 | 209 | inset_axes = inset_axes(parent_axes,
|
260 |
| - width="30%", # width = 30% of parent_bbox |
261 |
| - height=1., # height : 1 inch |
| 210 | + width="30%", # width = 30% of parent_bbox |
| 211 | + height=1., # height = 1 inch |
262 | 212 | loc='lower left')
|
263 | 213 |
|
264 | 214 | creates an inset axes whose width is 30% of the parent axes and whose
|
265 | 215 | height is fixed at 1 inch.
|
266 | 216 |
|
267 |
| -You may creates your inset whose size is determined so that the data |
268 |
| -scale of the inset axes to be that of the parent axes multiplied by |
269 |
| -some factor. For example, :: |
| 217 | +`.inset_locator.zoomed_inset_axes` creates an inset axes whose data scale is |
| 218 | +that of the parent axes multiplied by some factor, e.g. :: |
270 | 219 |
|
271 | 220 | inset_axes = zoomed_inset_axes(ax,
|
272 |
| - 0.5, # zoom = 0.5 |
| 221 | + 0.5, # zoom = 0.5 |
273 | 222 | loc='upper right')
|
274 | 223 |
|
275 |
| -creates an inset axes whose data scale is half of the parent axes. |
276 |
| -Here is complete examples. |
| 224 | +creates an inset axes whose data scale is half of the parent axes. This can be |
| 225 | +useful to mark the zoomed area on the parent axes: |
277 | 226 |
|
278 | 227 | .. figure:: ../../gallery/axes_grid1/images/sphx_glr_inset_locator_demo_001.png
|
279 | 228 | :target: ../../gallery/axes_grid1/inset_locator_demo.html
|
280 | 229 | :align: center
|
281 | 230 | :scale: 50
|
282 | 231 |
|
283 |
| - Inset Locator Demo |
284 |
| -
|
285 |
| -For example, :func:`.zoomed_inset_axes` can be used when you want the |
286 |
| -inset represents the zoom-up of the small portion in the parent axes. |
287 |
| -And :mod:`~mpl_toolkits.axes_grid1.inset_locator` provides a helper |
288 |
| -function :func:`.mark_inset` to mark the location of the area |
289 |
| -represented by the inset axes. |
| 232 | +`.inset_locator.mark_inset` allows marking the location of the area represented |
| 233 | +by the inset axes: |
290 | 234 |
|
291 | 235 | .. figure:: ../../gallery/axes_grid1/images/sphx_glr_inset_locator_demo2_001.png
|
292 | 236 | :target: ../../gallery/axes_grid1/inset_locator_demo2.html
|
293 | 237 | :align: center
|
294 | 238 | :scale: 50
|
295 | 239 |
|
296 |
| - Inset Locator Demo2 |
297 |
| -
|
298 |
| -
|
299 |
| -RGB Axes |
300 |
| -~~~~~~~~ |
| 240 | +RGBAxes |
| 241 | +------- |
301 | 242 |
|
302 | 243 | RGBAxes is a helper class to conveniently show RGB composite
|
303 | 244 | images. Like ImageGrid, the location of axes are adjusted so that the
|
|
311 | 252 | r, g, b = get_rgb() # r, g, b are 2D images.
|
312 | 253 | ax.imshow_rgb(r, g, b)
|
313 | 254 |
|
314 |
| -
|
315 | 255 | .. figure:: ../../gallery/axes_grid1/images/sphx_glr_demo_axes_rgb_001.png
|
316 | 256 | :target: ../../gallery/axes_grid1/demo_axes_rgb.html
|
317 | 257 | :align: center
|
318 | 258 | :scale: 50
|
319 | 259 |
|
320 |
| -
|
321 | 260 | AxesDivider
|
322 | 261 | ===========
|
323 | 262 |
|
|
0 commit comments