5
5
Customizing Location of Subplot Using GridSpec
6
6
**********************************************
7
7
8
- `` GridSpec ` `
8
+ :class: ` ~matplotlib.gridspec. GridSpec `
9
9
specifies the geometry of the grid that a subplot will be
10
10
placed. The number of rows and number of columns of the grid
11
11
need to be set. Optionally, the subplot layout parameters
12
12
(e.g., left, right, etc.) can be tuned.
13
13
14
- `` SubplotSpec ` `
14
+ :class: ` ~matplotlib.gridspec. SubplotSpec `
15
15
specifies the location of the subplot in the given *GridSpec *.
16
16
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.
20
20
21
21
22
22
Basic Example of using subplot2grid
23
23
===================================
24
24
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::
27
28
28
- ax = plt.subplot2grid((2,2),(0, 0))
29
+ ax = plt.subplot2grid((2, 2), (0, 0))
29
30
30
31
is identical to ::
31
32
32
- ax = plt.subplot(2,2, 1)
33
+ ax = plt.subplot(2, 2, 1)
33
34
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 .
35
36
36
37
To create a subplot that spans multiple cells, ::
37
38
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)
40
41
41
42
For example, the following commands ::
42
43
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))
48
49
49
50
creates
50
51
@@ -54,47 +55,48 @@ creates
54
55
GridSpec and SubplotSpec
55
56
========================
56
57
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.
58
60
59
61
For example, ::
60
62
61
- ax = plt.subplot2grid((2,2),(0, 0))
63
+ ax = plt.subplot2grid((2, 2), (0, 0))
62
64
63
65
is equal to ::
64
66
65
67
import matplotlib.gridspec as gridspec
66
68
gs = gridspec.GridSpec(2, 2)
67
69
ax = plt.subplot(gs[0, 0])
68
70
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
71
73
cells, use slice. ::
72
74
73
- ax2 = plt.subplot(gs[1,:-1])
75
+ ax2 = plt.subplot(gs[1, :-1])
74
76
ax3 = plt.subplot(gs[1:, -1])
75
77
76
78
The above example becomes ::
77
79
78
80
gs = gridspec.GridSpec(3, 3)
79
81
ax1 = plt.subplot(gs[0, :])
80
- ax2 = plt.subplot(gs[1,:-1])
82
+ ax2 = plt.subplot(gs[1, :-1])
81
83
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])
84
86
85
87
.. plot :: users/plotting/examples/demo_gridspec02.py
86
88
87
89
Adjust GridSpec layout
88
90
======================
89
91
90
92
When 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 . ::
92
94
93
95
gs1 = gridspec.GridSpec(3, 3)
94
96
gs1.update(left=0.05, right=0.48, wspace=0.05)
95
97
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.
98
100
99
101
The code below ::
100
102
@@ -117,8 +119,9 @@ creates
117
119
GridSpec using SubplotSpec
118
120
==========================
119
121
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. ::
122
125
123
126
gs0 = gridspec.GridSpec(1, 2)
124
127
@@ -132,8 +135,8 @@ parameters are set to that of the location of the given SubplotSpec. ::
132
135
A Complex Nested GridSpec using SubplotSpec
133
136
===========================================
134
137
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
137
140
spines in each of the inner 3x3 grids.
138
141
139
142
.. plot :: users/plotting/examples/demo_gridspec06.py
@@ -147,8 +150,8 @@ relative heights and widths of rows and columns. Note that absolute
147
150
values are meaningless, only their relative ratios matter. ::
148
151
149
152
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]
152
155
)
153
156
154
157
ax1 = plt.subplot(gs[0])
0 commit comments