You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"The ``Figure`` is the top-level container in this hierarchy. It is the overall window/page that everything is drawn on. You can have multiple independent figures. However, ``Figure``s can contain multiple ``Axes``. \n",
146
+
"The ``Figure`` is the top-level container in this hierarchy. It is the overall window/page that everything is drawn on. You can have multiple independent figures and ``Figure``s can contain multiple ``Axes``. \n",
147
147
"\n",
148
-
"Most plotting ocurs on an ``Axes``. The axes is effectively the area that we plot data on and any ticks/labels/etc associated with it. Usually we'll set up an Axes with a call to ``subplot`` (which places Axes on a regular grid), so in most cases we'll deal with here, ``Axes`` and ``Subplot`` are synonymous. We'll be heavily using ``Axes`` instances for plotting, etc, so you'll be seeing a lot of these.\n",
148
+
"Most plotting ocurs on an ``Axes``. The axes is effectively the area that we plot data on and any ticks/labels/etc associated with it. Usually we'll set up an Axes with a call to ``subplot`` (which places Axes on a regular grid), so in most cases, ``Axes`` and ``Subplot`` are synonymous.\n",
149
149
"\n",
150
-
"Each ``Axes`` has an ``XAxis`` and a ``YAxis``. These contain the ticks, tick locations, labels, etc. In this tutorial, we'll mostly control ticks, tick labels, and data limits through other mechanisms, so we won't touch the individual ``Axis`` part of things much at all. However, it's worth mentioning here to explain where the term ``Axes`` comes from.\n"
150
+
"Each ``Axes`` has an ``XAxis`` and a ``YAxis``. These contain the ticks, tick locations, labels, etc. In this tutorial, we'll mostly control ticks, tick labels, and data limits through other mechanisms, so we won't touch the individual ``Axis`` part of things all that much. However, it's worth mentioning here to explain where the term ``Axes`` comes from.\n"
Copy file name to clipboardExpand all lines: AnatomyOfMatplotlib-Part2-Plotting_Methods_Overview.ipynb
+79-34Lines changed: 79 additions & 34 deletions
Original file line number
Diff line number
Diff line change
@@ -32,7 +32,7 @@
32
32
"\n",
33
33
"We've talked a lot about laying things out, etc, but we haven't talked about actually plotting data yet. Matplotlib has a number of different plotting functions -- many more than we'll cover here, in fact. There's a more complete list in the pyplot documentation, and matplotlib gallery is a great place to get examples of all of them. \n",
34
34
"\n",
35
-
"However, a full list and/or the gallery can be a bit overwhelming at first. Instead we'll condense it down a bit, give you a look at some of the ones you're most likely to use, and then go over a subset of those in more detail.\n",
35
+
"However, a full list and/or the gallery can be a bit overwhelming at first. Instead we'll condense it down and give you a look at some of the ones you're most likely to use, and then go over a subset of those in more detail.\n",
36
36
"\n",
37
37
"Here's a simplified visual overview of matplotlib's most commonly used plot types. Let's browse through these, and then we'll go over a few in more detail. Clicking on any of these images will take you to the code that generated them. We'll skip that for now, but feel browse through it later."
38
38
]
@@ -82,23 +82,20 @@
82
82
],
83
83
"language": "python",
84
84
"metadata": {},
85
-
"outputs": [],
86
-
"prompt_number": null
85
+
"outputs": []
87
86
},
88
87
{
89
88
"cell_type": "markdown",
90
89
"metadata": {},
91
90
"source": [
92
91
"# Input Data: 1D Series\n",
93
92
"\n",
94
-
"We've briefly mentioned `ax.plot(x, y)` and `ax.scatter(x, y)` to draw lines and points, respectively. We'll cover some of their options (markers, colors, linestyles, etc) in the next section.\n",
95
-
"\n",
96
-
"Rather than revisiting `plot` and `scatter`, let's move on to a couple of other common plot styles.\n",
93
+
"We've briefly mentioned `ax.plot(x, y)` and `ax.scatter(x, y)` to draw lines and points, respectively. We'll cover some of their options (markers, colors, linestyles, etc) in the next section. Let's move on to a couple of other common plot types.\n",
97
94
"\n",
98
95
"### Bar Plots: `ax.bar(...)` and `ax.barh(...)`\n",
99
96
"<img src=\"images/bar_example.png\">\n",
100
97
"\n",
101
-
"Bar plots are one of the most common plot types. Matplotlib's `ax.bar(...)` method can also plot general rectangles, but the default is optimized for a simple sequence of x, y values, where the rectangles have a constant width. There's also `ax.barh(...)`, which makes a constant-height assumption instead of a constant-width assumption."
98
+
"Bar plots are one of the most common plot types. Matplotlib's `ax.bar(...)` method can also plot general rectangles, but the default is optimized for a simple sequence of x, y values, where the rectangles have a constant width. There's also `ax.barh(...)` (for horizontal), which makes a constant-height assumption instead of a constant-width assumption."
"Note that we held on to what `ax.bar(...)` returned. Matplotlib plotting methods return an `Artist` or a sequence of artists. Anything you can see in a matplotlib figure/axes/etc is an `Artist` of some sort.\n",
129
+
"Note that we held on to what `ax.bar(...)` returned. Matplotlib plotting methods return an `Artist` or a sequence of artists. Anything you can see in a matplotlib figure/axes/etc is an `Artist` of some sort. Most of the time, you will not need to retain these returned objects. You will want to capture them for special customizing that may not be possible through the normal plotting mechanism.\n",
133
130
"\n",
134
131
"Let's re-visit that last example and modify what's plotted. In the case of `bar`, a container artist is returned, so we'll modify its contents instead of the container itself (thus `for bar in vert_bars`)."
135
132
]
@@ -141,7 +138,7 @@
141
138
"fig, ax = plt.subplots()\n",
142
139
"vert_bars = ax.bar(x, y, color='lightblue', align='center')\n",
143
140
"\n",
144
-
"# We could do this with two separate calls to `ax.bar` and numpy boolean indexing, as well.\n",
141
+
"# We could have also done this with two separate calls to `ax.bar` and numpy boolean indexing.\n",
"In short, `imshow` can interpolate and display large arrays very quickly, while `pcolormesh` and `pcolor` are much slower, but can handle much flexible (i.e. more than just rectangular) arrangements of cells.\n",
281
+
"In short, `imshow` can interpolate and display large arrays very quickly, while `pcolormesh` and `pcolor` are much slower, but can handle flexible (i.e. more than just rectangular) arrangements of cells.\n",
256
282
"\n",
257
283
"We won't dwell too much on the differences and overlaps here. They have overlapping capabilities, but different default behavior because their primary use-cases are a bit different (there's also `matshow`, which is `imshow` with different defaults). \n",
258
284
"\n",
259
285
"Instead we'll focus on what they have in common.\n",
260
286
"\n",
261
-
"`imshow`, `pcolor`, `pcolormesh`, `scatter`, and any other matplotlib plotting methods that map a range of data values onto a colormap return artists that are instances of `ScalarMappable.` In practice, what that means is a) you can display a colorbar for them, and b) they share several keyword arguments."
287
+
"`imshow`, `pcolor`, `pcolormesh`, `scatter`, and any other matplotlib plotting methods that map a range of data values onto a colormap will return artists that are instances of `ScalarMappable.` In practice, what that means is a) you can display a colorbar for them, and b) they share several keyword arguments."
262
288
]
263
289
},
264
290
{
@@ -267,7 +293,7 @@
267
293
"source": [
268
294
"### Colorbars\n",
269
295
"\n",
270
-
"Next, let's add a colorbar to the figure to display what colors correspond to values of `data` we've plotted. "
296
+
"Let's add a colorbar to the figure to display what colors correspond to values of `data` we've plotted. "
271
297
]
272
298
},
273
299
{
@@ -284,8 +310,7 @@
284
310
],
285
311
"language": "python",
286
312
"metadata": {},
287
-
"outputs": [],
288
-
"prompt_number": null
313
+
"outputs": []
289
314
},
290
315
{
291
316
"cell_type": "markdown",
@@ -309,8 +334,7 @@
309
334
],
310
335
"language": "python",
311
336
"metadata": {},
312
-
"outputs": [],
313
-
"prompt_number": null
337
+
"outputs": []
314
338
},
315
339
{
316
340
"cell_type": "markdown",
@@ -351,8 +375,7 @@
351
375
],
352
376
"language": "python",
353
377
"metadata": {},
354
-
"outputs": [],
355
-
"prompt_number": null
378
+
"outputs": []
356
379
},
357
380
{
358
381
"cell_type": "markdown",
@@ -373,8 +396,7 @@
373
396
],
374
397
"language": "python",
375
398
"metadata": {},
376
-
"outputs": [],
377
-
"prompt_number": null
399
+
"outputs": []
378
400
},
379
401
{
380
402
"cell_type": "markdown",
@@ -396,11 +418,34 @@
396
418
],
397
419
"language": "python",
398
420
"metadata": {},
399
-
"outputs": [],
400
-
"prompt_number": null
421
+
"outputs": []
422
+
},
423
+
{
424
+
"cell_type": "code",
425
+
"collapsed": false,
426
+
"input": [
427
+
"import numpy as np\n",
428
+
"import matplotlib.pyplot as plt\n",
429
+
"np.random.seed(1)\n",
430
+
"\n",
431
+
"# Generate random data with different ranges...\n",
0 commit comments