|
43 | 43 | fig1.tight_layout()
|
44 | 44 |
|
45 | 45 | ############################################################################
|
46 |
| -# For such a simple use case, :mod:`~matplotlib.gridspec` is perhaps overly |
47 |
| -# verbose. |
| 46 | +# For a simple use case such as this, :mod:`~matplotlib.gridspec` is |
| 47 | +# perhaps overly verbose. |
48 | 48 | # You have to create the figure and :class:`~matplotlib.gridspec.GridSpec`
|
49 |
| -# instance separately, then pass the elements gridspec instance to the |
| 49 | +# instance separately, then pass elements of gridspec instance to the |
50 | 50 | # :func:`~matplotlib.figure.Figure.add_subplot` method to create the axes
|
51 | 51 | # objects.
|
52 |
| -# The elements of the gridspec are accessed as if they where elements of |
53 |
| -# a numpy array of the same shape. |
| 52 | +# The elements of the gridspec are accessed in generally the same manner as |
| 53 | +# numpy arrays. |
54 | 54 |
|
55 | 55 | fig2 = plt.figure()
|
56 | 56 | spec2 = gridspec.GridSpec(ncols=2, nrows=2)
|
|
61 | 61 | fig2.tight_layout()
|
62 | 62 |
|
63 | 63 | #############################################################################
|
64 |
| -# When you want to have plots of different sizes, however, |
| 64 | +# When you want to have subplots of different sizes, however, |
65 | 65 | # :mod:`~matplotlib.gridspec` becomes indispensable and provides a couple
|
66 | 66 | # of options.
|
67 | 67 | # The method shown here initializes a uniform grid specification,
|
|
81 | 81 | fig3.tight_layout()
|
82 | 82 |
|
83 | 83 | ############################################################################
|
84 |
| -# This example shows off using the ``width_ratios`` and ``height_ratios`` |
85 |
| -# options. |
| 84 | +# Other option is to use the ``width_ratios`` and ``height_ratios`` |
| 85 | +# parameters. |
86 | 86 | # These keyword arguments are lists of numbers.
|
87 | 87 | # Note that absolute values are meaningless, only their relative ratios
|
88 | 88 | # matter.
|
89 | 89 | # That means that ``width_ratios=[2, 4, 8]`` is equivalent to
|
90 | 90 | # ``width_ratios=[1, 2, 4]`` within equally wide figures.
|
91 |
| -# We'll blindly create the axes within ``for`` loops since we won't need |
92 |
| -# them later. |
| 91 | +# For the sake of demonstration, we'll blindly create the axes within |
| 92 | +# ``for`` loops since we won't need them later. |
93 | 93 |
|
94 | 94 | fig4 = plt.figure()
|
95 | 95 | widths = [2, 3, 1.5]
|
|
106 | 106 |
|
107 | 107 | ############################################################################
|
108 | 108 | # Learning to use ``width_ratios`` and ``height_ratios`` is particularly
|
109 |
| -# useful since :func:`~matplotlib.pyplot.subplots` accepts them within the |
110 |
| -# ``gridspec_kw`` parameter. |
| 109 | +# useful since the top-level function :func:`~matplotlib.pyplot.subplots` |
| 110 | +# accepts them within the ``gridspec_kw`` parameter. |
111 | 111 | # For that matter, any parameter accepted by
|
112 | 112 | # :class:`~matplotlib.gridspec.GridSpec` can be passed to
|
113 | 113 | # :func:`~matplotlib.pyplot.subplots` via the ``gridspec_kw`` parameter.
|
|
133 | 133 |
|
134 | 134 | fig = plt.figure()
|
135 | 135 | gs1 = gridspec.GridSpec(nrows=3, ncols=3, left=0.05, right=0.48, wspace=0.05)
|
| 136 | +ax1 = fig.add_subplot(gs1[:-1, :]) |
| 137 | +ax2 = fig.add_subplot(gs1[-1, :-1]) |
| 138 | +ax3 = fig.add_subplot(gs1[-1, -1]) |
| 139 | + |
136 | 140 |
|
137 | 141 | ###############################################################################
|
138 | 142 | # This is similar to :func:`~matplotlib.pyplot.subplots_adjust`, but it only
|
|
165 | 169 | fig = plt.figure()
|
166 | 170 | gs0 = gridspec.GridSpec(1, 2)
|
167 | 171 |
|
168 |
| -gs00 = gridspec.GridSpecFromSubplotSpec(3, 3, subplot_spec=gs0[0]) |
169 |
| -gs01 = gridspec.GridSpecFromSubplotSpec(3, 3, subplot_spec=gs0[1]) |
| 172 | +gs00 = gridspec.GridSpecFromSubplotSpec(2, 3, subplot_spec=gs0[0]) |
| 173 | +gs01 = gridspec.GridSpecFromSubplotSpec(3, 2, subplot_spec=gs0[1]) |
| 174 | + |
| 175 | +for a in range(2): |
| 176 | + for b in range(3): |
| 177 | + fig.add_subplot(gs00[a, b]) |
| 178 | + fig.add_subplot(gs01[b, a]) |
| 179 | + |
| 180 | +fig.tight_layout() |
170 | 181 |
|
171 | 182 | ###############################################################################
|
172 | 183 | # A Complex Nested GridSpec using SubplotSpec
|
|
0 commit comments