|
124 | 124 | fig5.tight_layout()
|
125 | 125 |
|
126 | 126 |
|
127 |
| -############################################################################### |
128 |
| -# Using subplot2grid |
129 |
| -# ================== |
130 |
| -# |
131 |
| -# To use :func:`~matplotlib.pyplot.subplot2grid`, you provide geometry of |
132 |
| -# the grid and the location of the subplot in the grid. |
133 |
| -# For a simple single-cell subplot: |
134 |
| - |
135 |
| -fig = plt.figure() |
136 |
| -ax = plt.subplot2grid((2, 2), (0, 0), fig=fig) |
137 |
| - |
138 |
| - |
139 |
| -############################################################################### |
140 |
| -# The example above is the same as the more common approach shown below. |
141 |
| - |
142 |
| -fig = plt.figure() |
143 |
| -ax = fig.add_subplot(2, 2, 1) |
144 |
| - |
145 |
| -############################################################################### |
146 |
| -# Note that, unlike Matplotlib's subplot, the index starts from 0 in GridSpec. |
147 |
| -# |
148 |
| -# To create a subplot that spans multiple cells: |
149 |
| - |
150 |
| -fig = plt.figure() |
151 |
| -ax2 = plt.subplot2grid((3, 3), (1, 0), colspan=2, fig=fig) |
152 |
| -ax3 = plt.subplot2grid((3, 3), (1, 2), rowspan=2, fig=fig) |
153 |
| - |
154 |
| -############################################################################### |
155 |
| -# For example, see the output of the following commands: |
156 |
| - |
157 |
| -fig = plt.figure() |
158 |
| -ax1 = plt.subplot2grid((3, 3), (0, 0), colspan=3, fig=fig) |
159 |
| -ax2 = plt.subplot2grid((3, 3), (1, 0), colspan=2, fig=fig) |
160 |
| -ax3 = plt.subplot2grid((3, 3), (1, 2), rowspan=2, fig=fig) |
161 |
| -ax4 = plt.subplot2grid((3, 3), (2, 0), fig=fig) |
162 |
| -ax5 = plt.subplot2grid((3, 3), (2, 1), fig=fig) |
163 |
| -fig.tight_layout() |
164 |
| - |
165 | 127 | ###############################################################################
|
166 | 128 | # Fine Adjustments to a Gridspec Layout
|
167 | 129 | # =====================================
|
|
180 | 142 |
|
181 | 143 | fig = plt.figure()
|
182 | 144 | gs1 = gridspec.GridSpec(nrows=3, ncols=3, left=0.05, right=0.48,
|
183 |
| - wspace=0.05, fig=fig) |
| 145 | + wspace=0.05) |
184 | 146 | ax1 = fig.add_subplot(gs1[:-1, :])
|
185 | 147 | ax2 = fig.add_subplot(gs1[-1, :-1])
|
186 | 148 | ax3 = fig.add_subplot(gs1[-1, -1])
|
187 | 149 |
|
188 | 150 |
|
189 | 151 | gs2 = gridspec.GridSpec(nrows=3, ncols=3, left=0.55, right=0.98,
|
190 |
| - hspace=0.05, fig=fig) |
| 152 | + hspace=0.05) |
191 | 153 | ax4 = fig.add_subplot(gs2[:, :-1])
|
192 | 154 | ax5 = fig.add_subplot(gs2[:-1, -1])
|
193 | 155 | ax6 = fig.add_subplot(gs2[-1, -1])
|
|
0 commit comments