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

Skip to content

Commit 7a2971b

Browse files
authored
Merge pull request #16372 from anntzer/griddoc
Dedupe ImageGrid doc from tutorial and docstring.
2 parents 786ed93 + c328250 commit 7a2971b

3 files changed

Lines changed: 58 additions & 98 deletions

File tree

doc/missing-references.json

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
"button": [
2424
"doc/users/prev_whats_new/whats_new_3.1.0.rst:338"
2525
],
26+
"cbar_axes": [
27+
"lib/mpl_toolkits/axes_grid1/axes_grid.py:docstring of mpl_toolkits.axes_grid1.axes_grid.ImageGrid:48",
28+
"lib/mpl_toolkits/axisartist/axes_grid.py:docstring of mpl_toolkits.axisartist.axes_grid.ImageGrid:48"
29+
],
2630
"dividers": [
2731
"lib/mpl_toolkits/axes_grid1/colorbar.py:docstring of mpl_toolkits.axes_grid1.colorbar.ColorbarBase:29"
2832
],
@@ -792,8 +796,8 @@
792796
"doc/api/prev_api_changes/api_changes_1.5.0.rst:44"
793797
],
794798
"Size.from_any": [
795-
"lib/mpl_toolkits/axes_grid1/axes_grid.py:docstring of mpl_toolkits.axes_grid1.axes_grid.ImageGrid:73",
796-
"lib/mpl_toolkits/axisartist/axes_grid.py:docstring of mpl_toolkits.axisartist.axes_grid.ImageGrid:48"
799+
"lib/mpl_toolkits/axes_grid1/axes_grid.py:docstring of mpl_toolkits.axes_grid1.axes_grid.ImageGrid:60",
800+
"lib/mpl_toolkits/axisartist/axes_grid.py:docstring of mpl_toolkits.axisartist.axes_grid.ImageGrid:60"
797801
],
798802
"Style": [
799803
"doc/devel/MEP/MEP26.rst:68"
@@ -892,13 +896,13 @@
892896
"doc/api/prev_api_changes/api_changes_3.1.0.rst:933"
893897
],
894898
"axes_grid1": [
895-
"doc/index.rst:184"
899+
"doc/index.rst:154"
896900
],
897901
"axis.Axis.get_ticks_position": [
898902
"doc/api/prev_api_changes/api_changes_3.1.0.rst:821"
899903
],
900904
"axisartist": [
901-
"doc/index.rst:184"
905+
"doc/index.rst:154"
902906
],
903907
"backend_bases.RendererBase": [
904908
"lib/matplotlib/backends/backend_template.py:docstring of matplotlib.backends.backend_template.RendererTemplate:4"
@@ -1506,7 +1510,7 @@
15061510
"lib/mpl_toolkits/axisartist/axis_artist.py:docstring of mpl_toolkits.axisartist.axis_artist:26"
15071511
],
15081512
"mplot3d": [
1509-
"doc/index.rst:184"
1513+
"doc/index.rst:154"
15101514
],
15111515
"new_figure_manager": [
15121516
"doc/devel/MEP/MEP23.rst:75"
@@ -1689,4 +1693,4 @@
16891693
"lib/mpl_toolkits/mplot3d/axes3d.py:docstring of mpl_toolkits.mplot3d.axes3d.Axes3D.get_ylim3d:24"
16901694
]
16911695
}
1692-
}
1696+
}

lib/mpl_toolkits/axes_grid1/axes_grid.py

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,13 @@ def cla(self):
8282

8383
class Grid:
8484
"""
85-
A class that creates a grid of Axes. In matplotlib, the axes
86-
location (and size) is specified in the normalized figure
87-
coordinates. This may not be ideal for images that needs to be
88-
displayed with a given aspect ratio. For example, displaying
89-
images of a same size with some fixed padding between them cannot
90-
be easily done in matplotlib. AxesGrid is used in such case.
85+
A grid of Axes.
86+
87+
In Matplotlib, the axes location (and size) is specified in normalized
88+
figure coordinates. This may not be ideal for images that needs to be
89+
displayed with a given aspect ratio; for example, it is difficult to
90+
display multiple images of a same size with some fixed padding between
91+
them. AxesGrid can be used in such case.
9192
"""
9293

9394
_defaultAxesClass = Axes
@@ -115,14 +116,25 @@ def __init__(self, fig,
115116
rect : (float, float, float, float) or int
116117
The axes position, as a ``(left, bottom, width, height)`` tuple or
117118
as a three-digit subplot position code (e.g., "121").
119+
nrows_ncols : (int, int)
120+
Number of rows and columns in the grid.
121+
ngrids : int or None, default: None
122+
If not None, only the first *ngrids* axes in the grid are created.
118123
direction : {"row", "column"}, default: "row"
124+
Whether axes are created in row-major ("row by row") or
125+
column-major order ("column by column").
119126
axes_pad : float or (float, float), default: 0.02
120127
Padding or (horizontal padding, vertical padding) between axes, in
121128
inches.
122129
add_all : bool, default: True
130+
Whether to add the axes to the figure using `.Figure.add_axes`.
123131
share_all : bool, default: False
132+
Whether all axes share their x- and y-axis. Overrides *share_x*
133+
and *share_y*.
124134
share_x : bool, default: True
135+
Whether all axes of a column share their x-axis.
125136
share_y : bool, default: True
137+
Whether all axes of a row share their y-axis.
126138
label_mode : {"L", "1", "all"}, default: "L"
127139
Determines which axes will get tick labels:
128140
@@ -133,6 +145,8 @@ def __init__(self, fig,
133145
134146
axes_class : subclass of `matplotlib.axes.Axes`, default: None
135147
aspect : bool, default: False
148+
Whether the axes aspect ratio follows the aspect ratio of the data
149+
limits.
136150
"""
137151
self._nrows, self._ncols = nrows_ncols
138152

@@ -332,14 +346,7 @@ def get_vsize_hsize(self):
332346

333347

334348
class ImageGrid(Grid):
335-
"""
336-
A class that creates a grid of Axes. In matplotlib, the axes
337-
location (and size) is specified in the normalized figure
338-
coordinates. This may not be ideal for images that needs to be
339-
displayed with a given aspect ratio. For example, displaying
340-
images of a same size with some fixed padding between them cannot
341-
be easily done in matplotlib. ImageGrid is used in such case.
342-
"""
349+
# docstring inherited
343350

344351
_defaultCbarAxesClass = CbarAxes
345352

@@ -368,13 +375,24 @@ def __init__(self, fig,
368375
rect : (float, float, float, float) or int
369376
The axes position, as a ``(left, bottom, width, height)`` tuple or
370377
as a three-digit subplot position code (e.g., "121").
378+
nrows_ncols : (int, int)
379+
Number of rows and columns in the grid.
380+
ngrids : int or None, default: None
381+
If not None, only the first *ngrids* axes in the grid are created.
371382
direction : {"row", "column"}, default: "row"
372-
axes_pad : float or (float, float), default: 0.02
383+
Whether axes are created in row-major ("row by row") or
384+
column-major order ("column by column"). This also affects the
385+
order in which axes are accessed using indexing (``grid[index]``).
386+
axes_pad : float or (float, float), default: 0.02in
373387
Padding or (horizontal padding, vertical padding) between axes, in
374388
inches.
375389
add_all : bool, default: True
390+
Whether to add the axes to the figure using `.Figure.add_axes`.
376391
share_all : bool, default: False
392+
Whether all axes share their x- and y-axis.
377393
aspect : bool, default: True
394+
Whether the axes aspect ratio follows the aspect ratio of the data
395+
limits.
378396
label_mode : {"L", "1", "all"}, default: "L"
379397
Determines which axes will get tick labels:
380398
@@ -383,10 +401,16 @@ def __init__(self, fig,
383401
- "1": Only the bottom left axes is labelled.
384402
- "all": all axes are labelled.
385403
386-
cbar_mode : {"each", "single", "edge", None }, default: None
404+
cbar_mode : {"each", "single", "edge", None}, default: None
405+
Whether to create a colorbar for "each" axes, a "single" colorbar
406+
for the entire grid, colorbars only for axes on the "edge"
407+
determined by *cbar_location*, or no colorbars. The colorbars are
408+
stored in the :attr:`cbar_axes` attribute.
387409
cbar_location : {"left", "right", "bottom", "top"}, default: "right"
388410
cbar_pad : float, default: None
411+
Padding between the image axes and the colorbar axes.
389412
cbar_size : size specification (see `.Size.from_any`), default: "5%"
413+
Colorbar size.
390414
cbar_set_cax : bool, default: True
391415
If True, each axes in the grid has a *cax* attribute that is bound
392416
to associated *cbar_axes*.

tutorials/toolkits/axes_grid.py

Lines changed: 8 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,14 @@
4040
ImageGrid
4141
---------
4242
43-
A class that creates a grid of Axes. In matplotlib, the axes location
44-
(and size) is specified in the normalized figure coordinates. This may
45-
not be ideal for images that needs to be displayed with a given aspect
46-
ratio. For example, displaying images of a same size with some fixed
47-
padding between them cannot be easily done in matplotlib. ImageGrid is
48-
used in such case.
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.
4951
5052
.. figure:: ../../gallery/axes_grid1/images/sphx_glr_simple_axesgrid_001.png
5153
:target: ../../gallery/axes_grid1/simple_axesgrid.html
@@ -78,76 +80,6 @@
7880
your mouse in interactive backends) of one axes will affect all
7981
other shared axes.
8082
81-
When initialized, ImageGrid creates given number (*ngrids* or *ncols* *
82-
*nrows* if *ngrids* is None) of Axes instances. A sequence-like
83-
interface is provided to access the individual Axes instances (e.g.,
84-
grid[0] is the first Axes in the grid. See below for the order of
85-
axes).
86-
87-
ImageGrid takes following arguments,
88-
89-
============= ======== ================================================
90-
Name Default Description
91-
============= ======== ================================================
92-
fig
93-
rect
94-
nrows_ncols number of rows and cols. e.g., (2, 2)
95-
ngrids None number of grids. nrows x ncols if None
96-
direction "row" increasing direction of axes number. [row|column]
97-
axes_pad 0.02 pad between axes in inches
98-
add_all True Add axes to figures if True
99-
share_all False xaxis & yaxis of all axes are shared if True
100-
aspect True aspect of axes
101-
label_mode "L" location of tick labels thaw will be displayed.
102-
"1" (only the lower left axes),
103-
"L" (left most and bottom most axes),
104-
or "all".
105-
cbar_mode None [None|single|each]
106-
cbar_location "right" [right|top]
107-
cbar_pad None pad between image axes and colorbar axes
108-
cbar_size "5%" size of the colorbar
109-
axes_class None
110-
============= ======== ================================================
111-
112-
*rect*
113-
specifies the location of the grid. You can either specify
114-
coordinates of the rectangle to be used (e.g., (0.1, 0.1, 0.8, 0.8)
115-
as in the Axes), or the subplot-like position (e.g., "121").
116-
117-
*direction*
118-
means the increasing direction of the axes number.
119-
120-
*aspect*
121-
By default (False), widths and heights of axes in the grid are
122-
scaled independently. If True, they are scaled according to their
123-
data limits (similar to aspect parameter in Matplotlib).
124-
125-
*share_all*
126-
if True, xaxis and yaxis of all axes are shared.
127-
128-
*direction*
129-
direction of increasing axes number. For "row",
130-
131-
+---------+---------+
132-
| grid[0] | grid[1] |
133-
+---------+---------+
134-
| grid[2] | grid[3] |
135-
+---------+---------+
136-
137-
For "column",
138-
139-
+---------+---------+
140-
| grid[0] | grid[2] |
141-
+---------+---------+
142-
| grid[1] | grid[3] |
143-
+---------+---------+
144-
145-
You can also create a colorbar (or colorbars). You can have colorbar
146-
for each axes (cbar_mode="each"), or you can have a single colorbar
147-
for the grid (cbar_mode="single"). The colorbar can be placed on your
148-
right, or top. The axes for each colorbar is stored as a *cbar_axes*
149-
attribute.
150-
15183
The examples below show what you can do with ImageGrid.
15284
15385
.. figure:: ../../gallery/axes_grid1/images/sphx_glr_demo_axes_grid_001.png

0 commit comments

Comments
 (0)