|
120 | 120 | "source": [ |
121 | 121 | "import proplot as plot\n", |
122 | 122 | "import numpy as np\n", |
123 | | - "f, axs = plot.subplots(ncols=3, nrows=3, axwidth=1.2)\n", |
| 123 | + "f, axs = plot.subplots(ncols=3, nrows=3, axwidth=1.4)\n", |
124 | 124 | "state = np.random.RandomState(51423)\n", |
125 | 125 | "m = axs.pcolormesh(\n", |
126 | 126 | " state.rand(20, 20), cmap='grays',\n", |
|
145 | 145 | "import proplot as plot\n", |
146 | 146 | "import numpy as np\n", |
147 | 147 | "f, axs = plot.subplots(\n", |
148 | | - " ncols=2, nrows=2, axwidth=1.3,\n", |
| 148 | + " ncols=2, nrows=2, axwidth=1.7,\n", |
149 | 149 | " share=0, wspace=0.3, order='F'\n", |
150 | 150 | ")\n", |
151 | 151 | "\n", |
|
164 | 164 | "f.colorbar(m[0], label='colorbar label', loc='l')\n", |
165 | 165 | "f.legend(hs, ncols=2, center=True, frame=False, loc='b', col=2)\n", |
166 | 166 | "f.legend(hs, ncols=1, label='legend label', frame=False, loc='r')\n", |
167 | | - "axs.format(suptitle='Figure colorbars and legends demo',\n", |
168 | | - " abc=True, abcloc='ul', abcstyle='A')\n", |
| 167 | + "axs.format(\n", |
| 168 | + " suptitle='Figure colorbars and legends demo',\n", |
| 169 | + " abc=True, abcloc='ul', abcstyle='A'\n", |
| 170 | + ")\n", |
169 | 171 | "for ax, title in zip(axs, ['2D dataset #1', '2D dataset #2', 'Line set #1', 'Line set #2']):\n", |
170 | 172 | " ax.format(xlabel='xlabel', title=title)" |
171 | 173 | ] |
|
196 | 198 | "source": [ |
197 | 199 | "import proplot as plot\n", |
198 | 200 | "import numpy as np\n", |
199 | | - "f, axs = plot.subplots(share=0, ncols=2)\n", |
| 201 | + "f, axs = plot.subplots(share=0, ncols=2, axwidth=2)\n", |
200 | 202 | "\n", |
201 | 203 | "# Colorbars from lines\n", |
202 | 204 | "ax = axs[0]\n", |
203 | 205 | "state = np.random.RandomState(51423)\n", |
204 | 206 | "data = 1 + (state.rand(12, 10) - 0.45).cumsum(axis=0)\n", |
205 | 207 | "cycle = plot.Cycle('algae')\n", |
206 | | - "hs = ax.plot(data, lw=4, cycle=cycle, colorbar='lr', colorbar_kw={\n", |
207 | | - " 'length': '8em', 'label': 'from lines'})\n", |
208 | | - "ax.colorbar(hs, loc='t', values=2*np.linspace(0.5, 9.5, 10),\n", |
209 | | - " label='from lines', length=0.7, ticks=2)\n", |
| 208 | + "hs = ax.plot(\n", |
| 209 | + " data, lw=4, cycle=cycle, colorbar='lr',\n", |
| 210 | + " colorbar_kw={'length': '8em', 'label': 'from lines'}\n", |
| 211 | + ")\n", |
| 212 | + "ax.colorbar(\n", |
| 213 | + " hs, loc='t', values=2*np.linspace(0.5, 9.5, 10),\n", |
| 214 | + " label='from lines', length=0.7, ticks=2\n", |
| 215 | + ")\n", |
210 | 216 | "\n", |
211 | 217 | "# Colorbars from a mappable\n", |
212 | 218 | "ax = axs[1]\n", |
213 | | - "m = ax.contourf(data.T, extend='both', cmap='algae',\n", |
214 | | - " levels=plot.arange(0, 3, 0.5))\n", |
215 | | - "f.colorbar(m, length=1, loc='r', label='inside ticks',\n", |
216 | | - " tickloc='left')\n", |
217 | | - "ax.colorbar(m, loc='ul', length=1, tickminor=True, drawedges=True, extendrect=True,\n", |
218 | | - " label='inset colorbar', labelcolor='gray7', labelweight='bold',\n", |
219 | | - " linewidth=1, edgecolor='gray7', ticklabelcolor='gray7', alpha=0.5)\n", |
220 | | - "axs.format(suptitle='Colorbar formatting demo',\n", |
221 | | - " xlabel='xlabel', ylabel='ylabel', top=False)" |
| 219 | + "m = ax.contourf(\n", |
| 220 | + " data.T, extend='both', cmap='algae',\n", |
| 221 | + " levels=plot.arange(0, 3, 0.5)\n", |
| 222 | + ")\n", |
| 223 | + "f.colorbar(\n", |
| 224 | + " m, length=1, loc='r', label='inside ticks',\n", |
| 225 | + " tickloc='left'\n", |
| 226 | + ")\n", |
| 227 | + "ax.colorbar(\n", |
| 228 | + " m, loc='ul', length=1, tickminor=True, drawedges=True,\n", |
| 229 | + " label='inset colorbar', labelcolor='gray7', labelweight='bold',\n", |
| 230 | + " linewidth=1, edgecolor='gray7', ticklabelcolor='gray7', alpha=0.5\n", |
| 231 | + ")\n", |
| 232 | + "axs.format(\n", |
| 233 | + " suptitle='Colorbar formatting demo',\n", |
| 234 | + " xlabel='xlabel', ylabel='ylabel', top=False\n", |
| 235 | + ")" |
222 | 236 | ] |
223 | 237 | }, |
224 | 238 | { |
|
249 | 263 | "import numpy as np\n", |
250 | 264 | "plot.rc.cycle = 'contrast'\n", |
251 | 265 | "labels = ['a', 'bb', 'ccc', 'dddd', 'eeeee']\n", |
252 | | - "f, axs = plot.subplots(ncols=2, span=False, share=1)\n", |
| 266 | + "f, axs = plot.subplots(ncols=2, span=False, share=1, axwidth=2)\n", |
253 | 267 | "hs1, hs2 = [], []\n", |
254 | 268 | "\n", |
255 | 269 | "# On-the-fly legends\n", |
256 | 270 | "state = np.random.RandomState(51423)\n", |
257 | 271 | "for i, label in enumerate(labels):\n", |
258 | | - " data = (state.rand(20)-0.45).cumsum(axis=0)\n", |
259 | | - " h1 = axs[0].plot(data, lw=4, label=label, legend='ul',\n", |
260 | | - " legend_kw={'order': 'F', 'title': 'column major'}) # add to legend in upper left\n", |
| 272 | + " data = (state.rand(20) - 0.45).cumsum(axis=0)\n", |
| 273 | + " h1 = axs[0].plot(\n", |
| 274 | + " data, lw=4, label=label, legend='ul',\n", |
| 275 | + " legend_kw={'order': 'F', 'title': 'column major'}\n", |
| 276 | + " )\n", |
261 | 277 | " hs1.extend(h1)\n", |
262 | | - " h2 = axs[1].plot(data, lw=4, label=label, legend='r', cycle='floral',\n", |
263 | | - " legend_kw={'ncols': 1, 'frame': False, 'title': 'no frame'}) # add to legend in right panel\n", |
| 278 | + " h2 = axs[1].plot(\n", |
| 279 | + " data, lw=4, label=label, legend='r', cycle='floral',\n", |
| 280 | + " legend_kw={'ncols': 1, 'frame': False, 'title': 'no frame'}\n", |
| 281 | + " )\n", |
264 | 282 | " hs2.extend(h2)\n", |
265 | 283 | " \n", |
266 | 284 | "# Outer legends\n", |
267 | 285 | "ax = axs[0]\n", |
268 | | - "ax.legend(hs1, loc='b', ncols=3, linewidth=2, title='row major', order='C',\n", |
269 | | - " edgecolor='gray4', facecolor='gray2')\n", |
| 286 | + "ax.legend(\n", |
| 287 | + " hs1, loc='b', ncols=3, linewidth=2,title='row major', order='C',\n", |
| 288 | + " facecolor='gray2'\n", |
| 289 | + ")\n", |
270 | 290 | "ax = axs[1]\n", |
271 | 291 | "ax.legend(hs2, loc='b', ncols=3, center=True, title='centered rows')\n", |
272 | 292 | "axs.format(xlabel='xlabel', ylabel='ylabel', suptitle='Legend formatting demo')" |
|
0 commit comments