55Customizing Location of Subplot Using GridSpec
66**********************************************
77
8- `` GridSpec ` `
8+ :class: ` ~matplotlib.gridspec. GridSpec `
99 specifies the geometry of the grid that a subplot will be
1010 placed. The number of rows and number of columns of the grid
1111 need to be set. Optionally, the subplot layout parameters
1212 (e.g., left, right, etc.) can be tuned.
1313
14- `` SubplotSpec ` `
14+ :class: ` ~matplotlib.gridspec. SubplotSpec `
1515 specifies the location of the subplot in the given *GridSpec *.
1616
17- `` subplot2grid ` `
18- a helper function that is similar to " pyplot.subplot" but uses
19- 0-based indexing and let subplot to occupy multiple cells.
17+ :func: ` ~matplotlib.pyplot. subplot2grid `
18+ a helper function that is similar to :func: ` ~matplotlib. pyplot.subplot`
19+ but uses 0-based indexing and let subplot to occupy multiple cells.
2020
2121
2222Basic Example of using subplot2grid
2323===================================
2424
25- To use subplot2grid, you provide geometry of the grid and the location
26- of the subplot in the grid. For a simple single-cell subplot::
25+ To use :func: `~matplotlib.pyplot.subplot2grid `, you provide geometry of
26+ the grid and the location of the subplot in the grid. For a simple
27+ single-cell subplot::
2728
28- ax = plt.subplot2grid((2,2),(0, 0))
29+ ax = plt.subplot2grid((2, 2), (0, 0))
2930
3031is identical to ::
3132
32- ax = plt.subplot(2,2, 1)
33+ ax = plt.subplot(2, 2, 1)
3334
34- Note that, unlike matplotlib 's subplot, the index starts from 0 in gridspec .
35+ Note that, unlike Matplotlib 's subplot, the index starts from 0 in GridSpec .
3536
3637To create a subplot that spans multiple cells, ::
3738
38- ax2 = plt.subplot2grid((3,3), (1, 0), colspan=2)
39- ax3 = plt.subplot2grid((3,3), (1, 2), rowspan=2)
39+ ax2 = plt.subplot2grid((3, 3), (1, 0), colspan=2)
40+ ax3 = plt.subplot2grid((3, 3), (1, 2), rowspan=2)
4041
4142For example, the following commands ::
4243
43- ax1 = plt.subplot2grid((3,3), (0,0), colspan=3)
44- ax2 = plt.subplot2grid((3,3), (1,0), colspan=2)
45- ax3 = plt.subplot2grid((3,3), (1, 2), rowspan=2)
46- ax4 = plt.subplot2grid((3,3), (2, 0))
47- ax5 = plt.subplot2grid((3,3), (2, 1))
44+ ax1 = plt.subplot2grid((3, 3), (0, 0), colspan=3)
45+ ax2 = plt.subplot2grid((3, 3), (1, 0), colspan=2)
46+ ax3 = plt.subplot2grid((3, 3), (1, 2), rowspan=2)
47+ ax4 = plt.subplot2grid((3, 3), (2, 0))
48+ ax5 = plt.subplot2grid((3, 3), (2, 1))
4849
4950creates
5051
@@ -54,47 +55,48 @@ creates
5455GridSpec and SubplotSpec
5556========================
5657
57- You can create GridSpec explicitly and use them to create a Subplot.
58+ You can create :class: `~matplotlib.gridspec.GridSpec ` explicitly and use
59+ them to create a subplot.
5860
5961For example, ::
6062
61- ax = plt.subplot2grid((2,2),(0, 0))
63+ ax = plt.subplot2grid((2, 2), (0, 0))
6264
6365is equal to ::
6466
6567 import matplotlib.gridspec as gridspec
6668 gs = gridspec.GridSpec(2, 2)
6769 ax = plt.subplot(gs[0, 0])
6870
69- A gridspec instance provides array-like (2d or 1d) indexing that
70- returns the SubplotSpec instance. For, SubplotSpec that spans multiple
71+ A GridSpec instance provides array-like (2d or 1d) indexing that
72+ returns the SubplotSpec instance. For a SubplotSpec that spans multiple
7173cells, use slice. ::
7274
73- ax2 = plt.subplot(gs[1,:-1])
75+ ax2 = plt.subplot(gs[1, :-1])
7476 ax3 = plt.subplot(gs[1:, -1])
7577
7678The above example becomes ::
7779
7880 gs = gridspec.GridSpec(3, 3)
7981 ax1 = plt.subplot(gs[0, :])
80- ax2 = plt.subplot(gs[1,:-1])
82+ ax2 = plt.subplot(gs[1, :-1])
8183 ax3 = plt.subplot(gs[1:, -1])
82- ax4 = plt.subplot(gs[-1,0])
83- ax5 = plt.subplot(gs[-1,-2])
84+ ax4 = plt.subplot(gs[-1, 0])
85+ ax5 = plt.subplot(gs[-1, -2])
8486
8587.. plot :: users/plotting/examples/demo_gridspec02.py
8688
8789Adjust GridSpec layout
8890======================
8991
9092When a GridSpec is explicitly used, you can adjust the layout
91- parameters of subplots that are created from the gridspec . ::
93+ parameters of subplots that are created from the GridSpec . ::
9294
9395 gs1 = gridspec.GridSpec(3, 3)
9496 gs1.update(left=0.05, right=0.48, wspace=0.05)
9597
96- This is similar to * subplots_adjust * , but it only affects the subplots
97- that are created from the given GridSpec.
98+ This is similar to :func: ` ~matplotlib.pyplot. subplots_adjust` , but it only
99+ affects the subplots that are created from the given GridSpec.
98100
99101The code below ::
100102
@@ -117,8 +119,9 @@ creates
117119GridSpec using SubplotSpec
118120==========================
119121
120- You can create GridSpec from the SubplotSpec, in which case its layout
121- parameters are set to that of the location of the given SubplotSpec. ::
122+ You can create GridSpec from the :class: `~matplotlib.gridspec.SubplotSpec `,
123+ in which case its layout parameters are set to that of the location of
124+ the given SubplotSpec. ::
122125
123126 gs0 = gridspec.GridSpec(1, 2)
124127
@@ -132,8 +135,8 @@ parameters are set to that of the location of the given SubplotSpec. ::
132135A Complex Nested GridSpec using SubplotSpec
133136===========================================
134137
135- Here's a more sophisticated example of nested gridspec where we put
136- a box around each cell of the outer 4x4 grid, by hiding appropriate
138+ Here's a more sophisticated example of nested GridSpec where we put
139+ a box around each cell of the outer 4x4 grid, by hiding appropriate
137140spines in each of the inner 3x3 grids.
138141
139142.. plot :: users/plotting/examples/demo_gridspec06.py
@@ -147,8 +150,8 @@ relative heights and widths of rows and columns. Note that absolute
147150values are meaningless, only their relative ratios matter. ::
148151
149152 gs = gridspec.GridSpec(2, 2,
150- width_ratios=[1,2],
151- height_ratios=[4,1]
153+ width_ratios=[1, 2],
154+ height_ratios=[4, 1]
152155 )
153156
154157 ax1 = plt.subplot(gs[0])
0 commit comments