|
301 | 301 | "cell_type": "markdown", |
302 | 302 | "metadata": {}, |
303 | 303 | "source": [ |
304 | | - "## Categorical bar plots" |
| 304 | + "## Bar plots" |
305 | 305 | ] |
306 | 306 | }, |
307 | 307 | { |
|
310 | 310 | "metadata": {}, |
311 | 311 | "outputs": [], |
312 | 312 | "source": [ |
313 | | - "# recommended: pass labels as x\n", |
314 | | - "labels = ['a', 'b', 'c', 'd']\n", |
315 | | - "plt.bar(labels, x**2)" |
316 | | - ] |
317 | | - }, |
318 | | - { |
319 | | - "cell_type": "markdown", |
320 | | - "metadata": {}, |
321 | | - "source": [ |
322 | | - "### Example: Multiple bars\n", |
323 | | - "\n", |
324 | | - "It's a pain, because you have to position and size them manually.\n", |
325 | | - "\n", |
326 | | - "We'll learn better ways later using pandas later." |
| 313 | + "x = [0, 1, 2, 3]\n", |
| 314 | + "y = [1, 4, 9, 16]\n", |
| 315 | + "plt.bar(x, y)" |
327 | 316 | ] |
328 | 317 | }, |
329 | 318 | { |
|
332 | 321 | "metadata": {}, |
333 | 322 | "outputs": [], |
334 | 323 | "source": [ |
335 | | - "plt.bar(x-0.2, x**2, width=0.4)\n", |
336 | | - "plt.bar(x+0.2, (0.5-x)**2, width=0.4)" |
| 324 | + "labels = ['a', 'b', 'c', 'd']\n", |
| 325 | + "plt.bar(labels, y)\n", |
| 326 | + "#plt.plot(x, y, 'ro')" |
337 | 327 | ] |
338 | 328 | }, |
339 | 329 | { |
|
342 | 332 | "source": [ |
343 | 333 | "## Other plotting functions\n", |
344 | 334 | "\n", |
| 335 | + "The concept is always the same:\n", |
| 336 | + "\n", |
| 337 | + "- an Axes method creates the data Artists and adds them to the Axes\n", |
| 338 | + "- the first few arguments describe the data\n", |
| 339 | + "- there are many optional keworda arguments to customize style and behavior\n", |
| 340 | + "\n", |
| 341 | + "\n", |
345 | 342 | "See\n", |
346 | 343 | "\n", |
347 | 344 | "- https://matplotlib.org/stable/plot_types/index.html\n", |
348 | | - "- https://matplotlib.org/stable/api/axes_api.html" |
| 345 | + "- https://matplotlib.org/stable/api/axes_api.html\n", |
| 346 | + "\n" |
349 | 347 | ] |
350 | 348 | }, |
| 349 | + { |
| 350 | + "cell_type": "code", |
| 351 | + "execution_count": null, |
| 352 | + "metadata": {}, |
| 353 | + "outputs": [], |
| 354 | + "source": [] |
| 355 | + }, |
351 | 356 | { |
352 | 357 | "cell_type": "code", |
353 | 358 | "execution_count": null, |
|
372 | 377 | "name": "python", |
373 | 378 | "nbconvert_exporter": "python", |
374 | 379 | "pygments_lexer": "ipython3", |
375 | | - "version": "3.10.4" |
| 380 | + "version": "3.11.4" |
376 | 381 | } |
377 | 382 | }, |
378 | 383 | "nbformat": 4, |
|
0 commit comments