8000 Copy-edit axes_grid tutorial. · matplotlib/matplotlib@7b2b6fd · GitHub
[go: up one dir, main page]

Skip to content

Commit 7b2b6fd

Browse files
committed
Copy-edit axes_grid tutorial.
Probably still needs further work (not in this PR), but hopefully an improvement over the current state...
1 parent a08e334 commit 7b2b6fd

File tree

1 file changed

+53
-117
lines changed

1 file changed

+53
-117
lines changed

tutorials/toolkits/axes_grid.py

Lines changed: 53 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -1,115 +1,84 @@
11
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-
92
.. _axes_grid1_users-guide-index:
103
4+
==========================================
5+
Overview of :mod:`mpl_toolkits.axes_grid1`
6+
==========================================
117
12-
What is axes_grid1 toolkit?
13-
===========================
8+
:mod:`.axes_grid1` provides the following features:
149
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).
2818
2919
.. figure:: ../../gallery/axes_grid1/images/sphx_glr_demo_axes_grid_001.png
3020
:target: ../../gallery/axes_grid1/demo_axes_grid.html
3121
:align: center
3222
:scale: 50
3323
34-
Demo Axes Grid
35-
36-
3724
axes_grid1
3825
==========
3926
4027
ImageGrid
4128
---------
4229
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 normally 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 its detailed API.
5135
5236
.. figure:: ../../gallery/axes_grid1/images/sphx_glr_simple_axesgrid_001.png
5337
:target: ../../gallery/axes_grid1/simple_axesgrid.html
5438
:align: center
5539
:scale: 50
5640
57-
Simple Axesgrid
58-
5941
* 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
6143
given rectangle (like the aspect of axes). Note that in this example,
6244
the paddings between axes are fixed even if you changes the figure
6345
size.
6446
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 a same column share their x-axis, and axes in a same row share their
48+
y-axis (in the sense of `~.Axes.sharex`, `~.Axes.sharey`). Additionally,
49+
Axes in a same column all have the same width, and axes in a same row all
50+
have the same height. These widths and heights are scaled in proportion to
51+
the axes' view limits (xlim or ylim).
6952
7053
.. figure:: ../../gallery/axes_grid1/images/sphx_glr_simple_axesgrid2_001.png
7154
:target: ../../gallery/axes_grid1/simple_axesgrid2.html
7255
:align: center
7356
:scale: 50
7457
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< 9E88 code>-
8358
The examples below show what you can do with ImageGrid.
8459
8560
.. figure:: ../../gallery/axes_grid1/images/sphx_glr_demo_axes_grid_001.png
8661
:target: ../../gallery/axes_grid1/demo_axes_grid.html
8762
:align: center
8863
:scale: 50
8964
90-
Demo Axes Grid
91-
92-
9365
AxesDivider Class
9466
-----------------
9567
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::
10376
10477
ax = subplot(1, 1, 1)
10578
divider = make_axes_locatable(ax)
10679
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.
11382
11483
colorbar whose height (or width) in sync with the master axes
11584
-------------------------------------------------------------
@@ -119,9 +88,6 @@
11988
:align: center
12089
:scale: 50
12190
122-
Simple Colorbar
123-
124-
12591
scatter_hist.py with AxesDivider
12692
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
12793
@@ -150,15 +116,12 @@
150116
:align: center
151117
:scale: 50
152118
153-
Scatter Hist
154-
155119
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
157121
original :doc:`/gallery/lines_bars_and_markers/scatter_hist` in Matplotlib.
158122
For example, you can set the aspect ratio of the scatter plot, even with the
159123
x-axis or y-axis is shared accordingly.
160124
161-
162125
ParasiteAxes
163126
------------
164127
@@ -181,7 +144,6 @@
181144
parasite axes. To create a host axes, you may use *host_subplot* or
182145
*host_axes* command.
183146
184-
185147
Example 1. twinx
186148
~~~~~~~~~~~~~~~~
187149
@@ -190,9 +152,6 @@
190152
:align: center
191153
:scale: 50
192154
193-
Parasite Simple
194-
195-
196155
Example 2. twin
197156
~~~~~~~~~~~~~~~
198157
@@ -206,98 +165,77 @@
206165
ax2.set_xticklabels(["0", r"$\frac{1}{2}\pi$",
207166
r"$\pi$", r"$\frac{3}{2}\pi$", r"$2\pi$"])
208167
209-
210168
.. figure:: ../../gallery/axes_grid1/images/sphx_glr_simple_axisline4_001.png
211169
:target: ../../gallery/axes_grid1/simple_axisline4.html
212170
:align: center
213171
:scale: 50
214172
215-
Simple Axisline4
216-
217173
A more sophisticated example using twin. Note that if you change the
218174
x-limit in the host axes, the x-limit of the parasite axes will change
219175
accordingly.
220176
221-
222177
.. figure:: ../../gallery/axes_grid1/images/sphx_glr_parasite_simple2_001.png
223178
:target: ../../gallery/axes_grid1/parasite_simple2.html
224179
:align: center
225180
:scale: 50
226181
227-
Parasite Simple2
228-
229-
230182
AnchoredArtists
231183
---------------
232184
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
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.
239190
240191
.. figure:: ../../gallery/axes_grid1/images/sphx_glr_simple_anchored_artists_001.png
241192
:target: ../../gallery/axes_grid1/simple_anchored_artists.html
242193
:align: center
243194
:scale: 50
244195
245-
Simple Anchored Artists
246-
247-
248196
InsetLocator
249197
------------
250198
251-
:mod:`mpl_toolkits.axes_grid1.inset_locator` provides helper classes
199+
:mod:`.axes_grid1.inset_locator` provides helper classes
252200
and functions to place your (inset) axes at the anchored position of
253201
the parent axes, similarly to AnchoredArtist.
254202
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::
203+
`.inset_locator.inset_axes` creates an inset axes whose size is either fixed,
204+
or a fixed proportion of the parent axes::
258205
259206
inset_axes = inset_axes(parent_axes,
260-
width="30%", # width = 30% of parent_bbox
261-
height=1., # height : 1 inch
207+
width="30%", # width = 30% of parent_bbox
208+
height=1., # height = 1 inch
262209
loc='lower left')
263210
264211
creates an inset axes whose width is 30% of the parent axes and whose
265212
height is fixed at 1 inch.
266213
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, ::
214+
`.inset_locator.zoomed_inset_axes` creates an inset axes whose data scale is
215+
that of the parent axes multiplied by some factor, e.g. ::
270216
271217
inset_axes = zoomed_inset_axes(ax,
272-
0.5, # zoom = 0.5
218+
0.5, # zoom = 0.5
273219
loc='upper right')
274220
275-
creates an inset axes whose data scale is half of the parent axes.
276-
Here is complete examples.
221+
creates an inset axes whose data scale is half of the parent axes. This can be
222+
useful to show a zoomed-up area of the parent axes:
277223
278224
.. figure:: ../../gallery/axes_grid1/images/sphx_glr_inset_locator_demo_001.png
279225
:target: ../../gallery/axes_grid1/inset_locator_demo.html
280226
:align: center
281227
:scale: 50
282228
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.
229+
`.inset_locator.mark_inset` allows marking the location of the area represented
230+
by the inset axes:
290231
291232
.. figure:: ../../gallery/axes_grid1/images/sphx_glr_inset_locator_demo2_001.png
292233
:target: ../../gallery/axes_grid1/inset_locator_demo2.html
293234
:align: center
294235
:scale: 50
295236
296-
Inset Locator Demo2
297-
298-
299-
RGB Axes
300-
~~~~~~~~
237+
RGBAxes
238+
~~~~~~~
301239
302240
RGBAxes is a helper class to conveniently show RGB composite
303241
images. Like ImageGrid, the location of axes are adjusted so that the
@@ -311,13 +249,11 @@
311249
r, g, b = get_rgb() # r, g, b are 2D images.
312250
ax.imshow_rgb(r, g, b)
313251
314-
315252
.. figure:: ../../gallery/axes_grid1/images/sphx_glr_demo_axes_rgb_001.png
316253
:target: ../../gallery/axes_grid1/demo_axes_rgb.html
317254
:align: center
318255
:scale: 50
319256
320-
321257
AxesDivider
322258
===========
323259

0 commit comments

Comments
 (0)
0