| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -210,10 +210,14 @@ def annotate_axes(ax, text, fontsize=18): | |||
| 210 | 210 | # Low-level and advanced grid methods | |
| 211 | 211 | # =================================== | |
| 212 | 212 | # | |
| 213 | - # `~.pyplot.subplots` and `~.pyplot.subplot_mosaic` provide high-level | ||
| 214 | - # interfaces to create `~.gridspec.GridSpec` objects and add associated | ||
| 215 | - # new Axes to a figure at given `~.gridspec.SubplotSpec` inside the | ||
| 216 | - # *GridSpec*. | ||
| 213 | + # Internally, the arrangement of a grid of Axes is controlled by creating | ||
| 214 | + # instances of `~.GridSpec` and `~.SubplotSpec`. GridSpec defines a | ||
| 215 | + # (possibly non-uniform) grid of cells. Indexing into the GridSpec returns | ||
| 216 | + # a SubplotSpec that covers one or more grid cells, and can be used to | ||
| 217 | + # specify the location of an Axes or "subplot". | ||
| 218 | + # | ||
| 219 | + # The following examples show how to use low-level methods to arrange Axes | ||
| 220 | + # using GridSpec objects. | ||
| 217 | 221 | # | |
| 218 | 222 | # Basic 2x2 grid | |
| 219 | 223 | # -------------- | |
@@ -233,13 +237,14 @@ def annotate_axes(ax, text, fontsize=18): | |||
| 233 | 237 | annotate_axes(ax3, 'ax3') | |
| 234 | 238 | fig.suptitle('Manually added subplots using add_gridspec') | |
| 235 | 239 | ||
| 236 | - ############################################################################# | ||
| 240 | + ############################################################################## | ||
| 237 | 241 | # Axes spanning rows or grids in a grid | |
| 238 | 242 | # ------------------------------------- | |
| 239 | 243 | # | |
| 240 | 244 | # We can index the *spec* array using `NumPy slice syntax | |
| 241 | 245 | # <https://numpy.org/doc/stable/reference/arrays.indexing.html>`_ | |
| 242 | - # and the new Axes will span the slice: | ||
| 246 | + # and the new Axes will span the slice. This would be the same | ||
| 247 | + # as ``fig, axd = plt.subplot_mosaic([['ax0', 'ax0'], ['ax1', 'ax2']], ...)``: | ||
| 243 | 248 | ||
| 244 | 249 | fig = plt.figure(figsize=(4.5, 3.5), constrained_layout=True) | |
| 245 | 250 | spec = fig.add_gridspec(2, 2) | |
@@ -252,7 +257,7 @@ def annotate_axes(ax, text, fontsize=18): | |||
| 252 | 257 | fig.suptitle('Manually added subplots, spanning a column') | |
| 253 | 258 | ||
| 254 | 259 | ############################################################################### | |
| 255 | - # Manual Adjustments to a Gridspec Layout | ||
| 260 | + # Manual adjustments to a GridSpec layout | ||
| 256 | 261 | # --------------------------------------- | |
| 257 | 262 | # | |
| 258 | 263 | # When a GridSpec is explicitly used, you can adjust the layout | |
@@ -261,6 +266,9 @@ def annotate_axes(ax, text, fontsize=18): | |||
| 261 | 266 | # `.Figure.tight_layout` which both ignore *left* and *right* and adjust | |
| 262 | 267 | # subplot sizes to fill the figure. Usually such manual placement | |
| 263 | 268 | # requires iterations to make the Axes tick labels not overlap the Axes. | |
| 269 | + # | ||
| 270 | + # These spacing parameters can also be passed to `~.pyplot.subplots` and | ||
| 271 | + # `~.pyplot.subplot_mosaic` as the *gridspec_kw* argument. | ||
| 264 | 272 | ||
| 265 | 273 | fig = plt.figure(constrained_layout=False, facecolor='0.9') | |
| 266 | 274 | gs = fig.add_gridspec(nrows=3, ncols=3, left=0.05, right=0.75, | |
@@ -275,7 +283,7 @@ def annotate_axes(ax, text, fontsize=18): | |||
| 275 | 283 | ||
| 276 | 284 | ############################################################################### | |
| 277 | 285 | # Nested layouts with SubplotSpec | |
| 278 | - # =============================== | ||
| 286 | + # ------------------------------- | ||
| 279 | 287 | # | |
| 280 | 288 | # You can create nested layout similar to `~.Figure.subfigures` using | |
| 281 | 289 | # `~.gridspec.SubplotSpec.subgridspec`. Here the Axes spines _are_ | |
@@ -305,9 +313,9 @@ def annotate_axes(ax, text, fontsize=18): | |||
| 305 | 313 | fig.suptitle('nested gridspecs') | |
| 306 | 314 | ||
| 307 | 315 | ############################################################################### | |
| 308 | - # Here's a more sophisticated example of nested GridSpec where we put | ||
| 309 | - # a box around each cell of the outer 4x4 grid, by hiding appropriate | ||
| 310 | - # spines in each of the inner 3x3 grids. | ||
| 316 | + # Here's a more sophisticated example of nested GridSpec: We create an outer | ||
| 317 | + # 4x4 grid with each cell containing and inner 3x3 grid of Axes. We outline the | ||
| 318 | + # outer 4x4 grid by hiding appropriate spines in each of the inner 3x3 grids. | ||
| 311 | 319 | ||
| 312 | 320 | ||
| 313 | 321 | def squiggle_xy(a, b, c, d, i=np.arange(0.0, 2*np.pi, 0.05)): | |
| Back | FazBrowse Home | New Git URL |
0 commit comments