|
31 | 31 | # Outer and inset locations
|
32 | 32 | # -------------------------
|
33 | 33 | #
|
34 |
| -# Matplotlib supports drawing "inset" legends and "outer" colorbars using |
35 |
| -# the `loc` and `location` keyword arguments. However, "outer" legends are |
36 |
| -# only posssible using the somewhat counterintuitive `bbox_to_anchor` keyword |
37 |
| -# (see `this stackoverflow post <https://stackoverflow.com/q/4700614/4970632>`__) |
| 34 | +# Matplotlib supports drawing "inset" legends and "outer" colorbars using the `loc` |
| 35 | +# and `location` keyword arguments. However, "outer" legends are only posssible using |
| 36 | +# the somewhat counterintuitive `bbox_to_anchor` keyword (see `here |
| 37 | +# <https://matplotlib.org/stable/tutorials/intermediate/legend_guide.html#legend-location>`__) |
38 | 38 | # and "inset" colorbars are not possible without manually creating and positioning
|
39 | 39 | # the associated axes. Proplot tries to improve this behavior:
|
40 | 40 | #
|
|
54 | 54 | # (e.g., ``loc='upper right'`` or the shorthand ``loc='ur'``). Inset
|
55 | 55 | # colorbars have optional background "frames" that can be configured
|
56 | 56 | # with various `~proplot.axes.Axes.colorbar` keywords.
|
| 57 | +# * Outer colorbars and legends can be aligned using the `align` keyword. |
57 | 58 |
|
58 | 59 | # `~proplot.axes.Axes.colorbar` and `~proplot.axes.Axes.legend` also both accept
|
59 | 60 | # `space` and `pad` keywords. `space` controls the absolute separation of the
|
|
139 | 140 | data = (state.rand(30, 10) - 0.5).cumsum(axis=0)
|
140 | 141 | ax = fig.subplot(121, title='On-the-fly legend')
|
141 | 142 | ax.plot( # add all at once
|
142 |
| - data[:, :5], lw=2, cycle='Blues1', cycle_kw={'ls': ('-', '--'), 'left': 0.1}, |
143 |
| - labels=labels, legend='l', legend_kw={'frame': False, 'ncols': 1} |
| 143 | + data[:, :5], lw=2, cycle='Reds1', cycle_kw={'ls': ('-', '--'), 'left': 0.1}, |
| 144 | + labels=labels, legend='b', legend_kw={'title': 'legend title'} |
144 | 145 | )
|
145 | 146 | for i in range(5):
|
146 | 147 | ax.plot( # add one-by-one
|
147 |
| - data[:, 5 + i], lw=2, cycle='Reds1', cycle_kw={'ls': ('-', '--'), 'left': 0.1}, |
148 |
| - label=labels[i], legend='b', legend_kw={'title': 'legend title'}, |
| 148 | + data[:, 5 + i], label=labels[i], linewidth=2, |
| 149 | + cycle='Blues1', cycle_kw={'N': 5, 'ls': ('-', '--'), 'left': 0.1}, |
149 | 150 | colorbar='ul', colorbar_kw={'label': 'colorbar from lines'}
|
150 | 151 | )
|
151 | 152 |
|
|
157 | 158 | colorbar_kw={'length': 0.8, 'label': 'colorbar label'},
|
158 | 159 | )
|
159 | 160 | ax.contour(
|
160 |
| - data, cmap='Mono_r', cmap_kw={'left': 0.05}, lw=1.5, |
161 |
| - colorbar='r', colorbar_kw={'label': 'colorbar label', 'length': 0.7}, |
162 |
| - label='contour', legend='ul', legend_kw={'label': 'legend from mappable'}, |
| 161 | + data, color='gray7', lw=1.5, |
| 162 | + label='contour', legend='ul', legend_kw={'label': 'legend from contours'}, |
163 | 163 | )
|
164 | 164 |
|
165 | 165 | # %%
|
|
0 commit comments