Skip to content

Commit dd04941

Browse files
committed
DOC: minor edits do data kwarg discussion + code style + links
1 parent dba20c6 commit dd04941

File tree

1 file changed

+28
-52
lines changed

1 file changed

+28
-52
lines changed

AnatomyOfMatplotlib-Part2-Plotting_Methods_Overview.ipynb

Lines changed: 28 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@
4747
{
4848
"cell_type": "code",
4949
"execution_count": null,
50-
"metadata": {
51-
"collapsed": false
52-
},
50+
"metadata": {},
5351
"outputs": [],
5452
"source": [
5553
"# Let's get our standard imports out of the way\n",
@@ -77,9 +75,7 @@
7775
{
7876
"cell_type": "code",
7977
"execution_count": null,
80-
"metadata": {
81-
"collapsed": false
82-
},
78+
"metadata": {},
8379
"outputs": [],
8480
"source": [
8581
"np.random.seed(1)\n",
@@ -111,9 +107,7 @@
111107
{
112108
"cell_type": "code",
113109
"execution_count": null,
114-
"metadata": {
115-
"collapsed": false
116-
},
110+
"metadata": {},
117111
"outputs": [],
118112
"source": [
119113
"fig, ax = plt.subplots()\n",
@@ -147,9 +141,7 @@
147141
{
148142
"cell_type": "code",
149143
"execution_count": null,
150-
"metadata": {
151-
"collapsed": false
152-
},
144+
"metadata": {},
153145
"outputs": [],
154146
"source": [
155147
"np.random.seed(1)\n",
@@ -171,9 +163,7 @@
171163
{
172164
"cell_type": "code",
173165
"execution_count": null,
174-
"metadata": {
175-
"collapsed": false
176-
},
166+
"metadata": {},
177167
"outputs": [],
178168
"source": [
179169
"x = np.linspace(0, 10, 200)\n",
@@ -197,17 +187,16 @@
197187
"metadata": {},
198188
"source": [
199189
"## `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",
201192
"\n",
202193
"Let's revisit the above example:"
203194
]
204195
},
205196
{
206197
"cell_type": "code",
207198
"execution_count": null,
208-
"metadata": {
209-
"collapsed": false
210-
},
199+
"metadata": {},
211200
"outputs": [],
212201
"source": [
213202
"x = np.linspace(0, 10, 200)\n",
@@ -242,9 +231,7 @@
242231
{
243232
"cell_type": "code",
244233
"execution_count": null,
245-
"metadata": {
246-
"collapsed": false
247-
},
234+
"metadata": {},
248235
"outputs": [],
249236
"source": [
250237
"%load exercises/2.1-bar_and_fill_between.py"
@@ -253,9 +240,7 @@
253240
{
254241
"cell_type": "code",
255242
"execution_count": null,
256-
"metadata": {
257-
"collapsed": false
258-
},
243+
"metadata": {},
259244
"outputs": [],
260245
"source": [
261246
"import numpy as np\n",
@@ -316,9 +301,7 @@
316301
{
317302
"cell_type": "code",
318303
"execution_count": null,
319-
"metadata": {
320-
"collapsed": false
321-
},
304+
"metadata": {},
322305
"outputs": [],
323306
"source": [
324307
"from matplotlib.cbook import get_sample_data\n",
@@ -342,9 +325,7 @@
342325
{
343326
"cell_type": "code",
344327
"execution_count": null,
345-
"metadata": {
346-
"collapsed": false
347-
},
328+
"metadata": {},
348329
"outputs": [],
349330
"source": [
350331
"fig, ax = plt.subplots()\n",
@@ -377,22 +358,22 @@
377358
" \n",
378359
"`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",
379360
"\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. "
381364
]
382365
},
383366
{
384367
"cell_type": "code",
385368
"execution_count": null,
386-
"metadata": {
387-
"collapsed": false
388-
},
369+
"metadata": {},
389370
"outputs": [],
390371
"source": [
391372
"from matplotlib.cbook import get_sample_data\n",
392373
"data = np.load(get_sample_data('axes_grid/bivariate_normal.npy'))\n",
393374
"\n",
394375
"fig, ax = plt.subplots()\n",
395-
"im = ax.imshow(data, cmap='seismic', interpolation='nearest')\n",
376+
"im = ax.imshow(data, cmap='seismic')\n",
396377
"fig.colorbar(im)\n",
397378
"plt.show()"
398379
]
@@ -407,13 +388,12 @@
407388
{
408389
"cell_type": "code",
409390
"execution_count": null,
410-
"metadata": {
411-
"collapsed": false
412-
},
391+
"metadata": {},
413392
"outputs": [],
414393
"source": [
415394
"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",
417397
" vmin=-2, vmax=2)\n",
418398
"fig.colorbar(im)\n",
419399
"plt.show()"
@@ -434,9 +414,7 @@
434414
{
435415
"cell_type": "code",
436416
"execution_count": null,
437-
"metadata": {
438-
"collapsed": false
439-
},
417+
"metadata": {},
440418
"outputs": [],
441419
"source": [
442420
"%load exercises/2.2-vmin_vmax_imshow_and_colorbars.py"
@@ -445,9 +423,7 @@
445423
{
446424
"cell_type": "code",
447425
"execution_count": null,
448-
"metadata": {
449-
"collapsed": false
450-
},
426+
"metadata": {},
451427
"outputs": [],
452428
"source": [
453429
"import numpy as np\n",
@@ -472,23 +448,23 @@
472448
],
473449
"metadata": {
474450
"kernelspec": {
475-
"display_name": "Python 2",
451+
"display_name": "Python 3",
476452
"language": "python",
477-
"name": "python2"
453+
"name": "python3"
478454
},
479455
"language_info": {
480456
"codemirror_mode": {
481457
"name": "ipython",
482-
"version": 2
458+
"version": 3
483459
},
484460
"file_extension": ".py",
485461
"mimetype": "text/x-python",
486462
"name": "python",
487463
"nbconvert_exporter": "python",
488-
"pygments_lexer": "ipython2",
489-
"version": "2.7.12"
464+
"pygments_lexer": "ipython3",
465+
"version": "3.6.5"
490466
}
491467
},
492468
"nbformat": 4,
493-
"nbformat_minor": 0
469+
"nbformat_minor": 1
494470
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy