Skip to content

Commit 654b223

Browse files
committed
Cleanup colorbar, legend, colormap-slicing examples
1 parent 46b69dc commit 654b223

File tree

2 files changed

+54
-30
lines changed

2 files changed

+54
-30
lines changed

docs/colorbars_legends.ipynb

Lines changed: 46 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@
120120
"source": [
121121
"import proplot as plot\n",
122122
"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",
124124
"state = np.random.RandomState(51423)\n",
125125
"m = axs.pcolormesh(\n",
126126
" state.rand(20, 20), cmap='grays',\n",
@@ -145,7 +145,7 @@
145145
"import proplot as plot\n",
146146
"import numpy as np\n",
147147
"f, axs = plot.subplots(\n",
148-
" ncols=2, nrows=2, axwidth=1.3,\n",
148+
" ncols=2, nrows=2, axwidth=1.7,\n",
149149
" share=0, wspace=0.3, order='F'\n",
150150
")\n",
151151
"\n",
@@ -164,8 +164,10 @@
164164
"f.colorbar(m[0], label='colorbar label', loc='l')\n",
165165
"f.legend(hs, ncols=2, center=True, frame=False, loc='b', col=2)\n",
166166
"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",
169171
"for ax, title in zip(axs, ['2D dataset #1', '2D dataset #2', 'Line set #1', 'Line set #2']):\n",
170172
" ax.format(xlabel='xlabel', title=title)"
171173
]
@@ -196,29 +198,41 @@
196198
"source": [
197199
"import proplot as plot\n",
198200
"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",
200202
"\n",
201203
"# Colorbars from lines\n",
202204
"ax = axs[0]\n",
203205
"state = np.random.RandomState(51423)\n",
204206
"data = 1 + (state.rand(12, 10) - 0.45).cumsum(axis=0)\n",
205207
"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",
210216
"\n",
211217
"# Colorbars from a mappable\n",
212218
"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+
")"
222236
]
223237
},
224238
{
@@ -249,24 +263,30 @@
249263
"import numpy as np\n",
250264
"plot.rc.cycle = 'contrast'\n",
251265
"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",
253267
"hs1, hs2 = [], []\n",
254268
"\n",
255269
"# On-the-fly legends\n",
256270
"state = np.random.RandomState(51423)\n",
257271
"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",
261277
" 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",
264282
" hs2.extend(h2)\n",
265283
" \n",
266284
"# Outer legends\n",
267285
"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",
270290
"ax = axs[1]\n",
271291
"ax.legend(hs2, loc='b', ncols=3, center=True, title='centered rows')\n",
272292
"axs.format(xlabel='xlabel', ylabel='ylabel', suptitle='Legend formatting demo')"

docs/colormaps.ipynb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,10 @@
267267
"source": [
268268
"import proplot as plot\n",
269269
"import numpy as np\n",
270-
"f, axs = plot.subplots([[0, 1, 1, 2, 2, 3, 3, 0], [4, 4, 5, 5, 6, 6, 7, 7]],\n",
271-
" axwidth=1.7, span=False)\n",
270+
"f, axs = plot.subplots(\n",
271+
" [[1, 1, 2, 2, 3, 3], [0, 4, 4, 5, 5, 0], [0, 6, 6, 7, 7, 0]],\n",
272+
" axwidth=1.7, span=False\n",
273+
")\n",
272274
"state = np.random.RandomState(51423)\n",
273275
"data = state.rand(40, 40).cumsum(axis=0) - 12\n",
274276
"\n",
@@ -281,8 +283,10 @@
281283
" title, cmap_kw = f'left={coord}', {'left': coord}\n",
282284
" else:\n",
283285
" title, cmap_kw = f'right={coord}', {'right': coord}\n",
284-
" ax.pcolormesh(data, cmap=cmap, cmap_kw=cmap_kw,\n",
285-
" colorbar='b', colorbar_kw={'locator': 'null'})\n",
286+
" ax.pcolormesh(\n",
287+
" data, cmap=cmap, cmap_kw=cmap_kw,\n",
288+
" colorbar='b', colorbar_kw={'locator': 'null'}\n",
289+
" )\n",
286290
" ax.format(xlabel='x axis', ylabel='y axis', title=title)\n",
287291
" \n",
288292
"# Cutting central colors\n",

0 commit comments

Comments
 (0)