|
47 | 47 | {
|
48 | 48 | "cell_type": "code",
|
49 | 49 | "execution_count": null,
|
50 |
| - "metadata": { |
51 |
| - "collapsed": false |
52 |
| - }, |
| 50 | + "metadata": {}, |
53 | 51 | "outputs": [],
|
54 | 52 | "source": [
|
55 | 53 | "# Let's get our standard imports out of the way\n",
|
|
77 | 75 | {
|
78 | 76 | "cell_type": "code",
|
79 | 77 | "execution_count": null,
|
80 |
| - "metadata": { |
81 |
| - "collapsed": false |
82 |
| - }, |
| 78 | + "metadata": {}, |
83 | 79 | "outputs": [],
|
84 | 80 | "source": [
|
85 | 81 | "np.random.seed(1)\n",
|
|
111 | 107 | {
|
112 | 108 | "cell_type": "code",
|
113 | 109 | "execution_count": null,
|
114 |
| - "metadata": { |
115 |
| - "collapsed": false |
116 |
| - }, |
| 110 | + "metadata": {}, |
117 | 111 | "outputs": [],
|
118 | 112 | "source": [
|
119 | 113 | "fig, ax = plt.subplots()\n",
|
|
147 | 141 | {
|
148 | 142 | "cell_type": "code",
|
149 | 143 | "execution_count": null,
|
150 |
| - "metadata": { |
151 |
| - "collapsed": false |
152 |
| - }, |
| 144 | + "metadata": {}, |
153 | 145 | "outputs": [],
|
154 | 146 | "source": [
|
155 | 147 | "np.random.seed(1)\n",
|
|
171 | 163 | {
|
172 | 164 | "cell_type": "code",
|
173 | 165 | "execution_count": null,
|
174 |
| - "metadata": { |
175 |
| - "collapsed": false |
176 |
| - }, |
| 166 | + "metadata": {}, |
177 | 167 | "outputs": [],
|
178 | 168 | "source": [
|
179 | 169 | "x = np.linspace(0, 10, 200)\n",
|
|
197 | 187 | "metadata": {},
|
198 | 188 | "source": [
|
199 | 189 | "## `data` keyword argument\n",
|
200 |
| - "When using specialized data structures such as Pandas DataFrame and XArray, the input data to be plotted are accessed like dictionary elements. This can get very repetitive and tedious as one types out a plotting command accessing those elements. So, the `data` keyword argument was added to many of the plotting functions in v1.5. With this feature, one can pass in a single dictionary-like object as `data`, and use the string key names in the place of the usual input data arguments.\n", |
| 190 | + "\n", |
| 191 | + "When using nested data structures such as h5py objects, Pandas DataFrames, or XArrays, the data can be accessed via `[]` like dictionary elements. This can get very repetitive and tedious as one types out a plotting command accessing those elements. So, the `data` keyword argument was added to almost all of the plotting functions in v1.5. With this feature, one can pass in a single dictionary-like object as `data`, and use the string key names in the place of the usual input data arguments.\n", |
201 | 192 | "\n",
|
202 | 193 | "Let's revisit the above example:"
|
203 | 194 | ]
|
204 | 195 | },
|
205 | 196 | {
|
206 | 197 | "cell_type": "code",
|
207 | 198 | "execution_count": null,
|
208 |
| - "metadata": { |
209 |
| - "collapsed": false |
210 |
| - }, |
| 199 | + "metadata": {}, |
211 | 200 | "outputs": [],
|
212 | 201 | "source": [
|
213 | 202 | "x = np.linspace(0, 10, 200)\n",
|
|
242 | 231 | {
|
243 | 232 | "cell_type": "code",
|
244 | 233 | "execution_count": null,
|
245 |
| - "metadata": { |
246 |
| - "collapsed": false |
247 |
| - }, |
| 234 | + "metadata": {}, |
248 | 235 | "outputs": [],
|
249 | 236 | "source": [
|
250 | 237 | "%load exercises/2.1-bar_and_fill_between.py"
|
|
253 | 240 | {
|
254 | 241 | "cell_type": "code",
|
255 | 242 | "execution_count": null,
|
256 |
| - "metadata": { |
257 |
| - "collapsed": false |
258 |
| - }, |
| 243 | + "metadata": {}, |
259 | 244 | "outputs": [],
|
260 | 245 | "source": [
|
261 | 246 | "import numpy as np\n",
|
|
316 | 301 | {
|
317 | 302 | "cell_type": "code",
|
318 | 303 | "execution_count": null,
|
319 |
| - "metadata": { |
320 |
| - "collapsed": false |
321 |
| - }, |
| 304 | + "metadata": {}, |
322 | 305 | "outputs": [],
|
323 | 306 | "source": [
|
324 | 307 | "from matplotlib.cbook import get_sample_data\n",
|
|
342 | 325 | {
|
343 | 326 | "cell_type": "code",
|
344 | 327 | "execution_count": null,
|
345 |
| - "metadata": { |
346 |
| - "collapsed": false |
347 |
| - }, |
| 328 | + "metadata": {}, |
348 | 329 | "outputs": [],
|
349 | 330 | "source": [
|
350 | 331 | "fig, ax = plt.subplots()\n",
|
|
377 | 358 | " \n",
|
378 | 359 | "`vmin` and `vmax` are particularly useful. Quite often, you'll want the colors to be mapped to a set range of data values, which aren't the min/max of your input data. For example, you might want a symmetric ranges of values around 0.\n",
|
379 | 360 | "\n",
|
380 |
| - "As an example of that, let's use a divergent colormap with the data we showed earlier. We'll also use `interpolation=\"nearest\"` to \"turn off\" interpolation of the cells in the input dataset:" |
| 361 | + "See the documentation for longer discussions of [colormaps](https://matplotlib.org/tutorials/colors/colormaps.html) and [norms](https://matplotlib.org/tutorials/colors/colormapnorms.html).\n", |
| 362 | + "\n", |
| 363 | + "As an example of that, let's use a divergent colormap with the data we showed earlier. " |
381 | 364 | ]
|
382 | 365 | },
|
383 | 366 | {
|
384 | 367 | "cell_type": "code",
|
385 | 368 | "execution_count": null,
|
386 |
| - "metadata": { |
387 |
| - "collapsed": false |
388 |
| - }, |
| 369 | + "metadata": {}, |
389 | 370 | "outputs": [],
|
390 | 371 | "source": [
|
391 | 372 | "from matplotlib.cbook import get_sample_data\n",
|
392 | 373 | "data = np.load(get_sample_data('axes_grid/bivariate_normal.npy'))\n",
|
393 | 374 | "\n",
|
394 | 375 | "fig, ax = plt.subplots()\n",
|
395 |
| - "im = ax.imshow(data, cmap='seismic', interpolation='nearest')\n", |
| 376 | + "im = ax.imshow(data, cmap='seismic')\n", |
396 | 377 | "fig.colorbar(im)\n",
|
397 | 378 | "plt.show()"
|
398 | 379 | ]
|
|
407 | 388 | {
|
408 | 389 | "cell_type": "code",
|
409 | 390 | "execution_count": null,
|
410 |
| - "metadata": { |
411 |
| - "collapsed": false |
412 |
| - }, |
| 391 | + "metadata": {}, |
413 | 392 | "outputs": [],
|
414 | 393 | "source": [
|
415 | 394 | "fig, ax = plt.subplots()\n",
|
416 |
| - "im = ax.imshow(data, cmap='seismic', interpolation='nearest',\n", |
| 395 | + "im = ax.imshow(data, \n", |
| 396 | + " cmap='seismic',\n", |
417 | 397 | " vmin=-2, vmax=2)\n",
|
418 | 398 | "fig.colorbar(im)\n",
|
419 | 399 | "plt.show()"
|
|
434 | 414 | {
|
435 | 415 | "cell_type": "code",
|
436 | 416 | "execution_count": null,
|
437 |
| - "metadata": { |
438 |
| - "collapsed": false |
439 |
| - }, |
| 417 | + "metadata": {}, |
440 | 418 | "outputs": [],
|
441 | 419 | "source": [
|
442 | 420 | "%load exercises/2.2-vmin_vmax_imshow_and_colorbars.py"
|
|
445 | 423 | {
|
446 | 424 | "cell_type": "code",
|
447 | 425 | "execution_count": null,
|
448 |
| - "metadata": { |
449 |
| - "collapsed": false |
450 |
| - }, |
| 426 | + "metadata": {}, |
451 | 427 | "outputs": [],
|
452 | 428 | "source": [
|
453 | 429 | "import numpy as np\n",
|
|
472 | 448 | ],
|
473 | 449 | "metadata": {
|
474 | 450 | "kernelspec": {
|
475 |
| - "display_name": "Python 2", |
| 451 | + "display_name": "Python 3", |
476 | 452 | "language": "python",
|
477 |
| - "name": "python2" |
| 453 | + "name": "python3" |
478 | 454 | },
|
479 | 455 | "language_info": {
|
480 | 456 | "codemirror_mode": {
|
481 | 457 | "name": "ipython",
|
482 |
| - "version": 2 |
| 458 | + "version": 3 |
483 | 459 | },
|
484 | 460 | "file_extension": ".py",
|
485 | 461 | "mimetype": "text/x-python",
|
486 | 462 | "name": "python",
|
487 | 463 | "nbconvert_exporter": "python",
|
488 |
| - "pygments_lexer": "ipython2", |
489 |
| - "version": "2.7.12" |
| 464 | + "pygments_lexer": "ipython3", |
| 465 | + "version": "3.6.5" |
490 | 466 | }
|
491 | 467 | },
|
492 | 468 | "nbformat": 4,
|
493 |
| - "nbformat_minor": 0 |
| 469 | + "nbformat_minor": 1 |
494 | 470 | }
|
0 commit comments