|
2 | 2 | "cells": [ |
3 | 3 | { |
4 | 4 | "cell_type": "markdown", |
5 | | - "metadata": {}, |
| 5 | + "metadata": { |
| 6 | + "editable": true, |
| 7 | + "slideshow": { |
| 8 | + "slide_type": "" |
| 9 | + }, |
| 10 | + "tags": [] |
| 11 | + }, |
6 | 12 | "source": [ |
7 | 13 | "<figure>\n", |
8 | 14 | " <IMG SRC=\"https://raw.githubusercontent.com/mbakker7/exploratory_computing_with_python/master/tudelft_logo.png\" WIDTH=250 ALIGN=\"right\">\n", |
|
14 | 20 | }, |
15 | 21 | { |
16 | 22 | "cell_type": "markdown", |
17 | | - "metadata": {}, |
| 23 | + "metadata": { |
| 24 | + "editable": true, |
| 25 | + "slideshow": { |
| 26 | + "slide_type": "" |
| 27 | + }, |
| 28 | + "tags": [] |
| 29 | + }, |
18 | 30 | "source": [ |
19 | 31 | "## Notebook 1: Basics and Plotting\n", |
20 | 32 | "### First Python steps\n", |
|
105 | 117 | }, |
106 | 118 | { |
107 | 119 | "cell_type": "markdown", |
108 | | - "metadata": {}, |
| 120 | + "metadata": { |
| 121 | + "editable": true, |
| 122 | + "slideshow": { |
| 123 | + "slide_type": "" |
| 124 | + }, |
| 125 | + "tags": [] |
| 126 | + }, |
109 | 127 | "source": [ |
110 | 128 | "### <a id=\"ex1a\"></a> Exercise 1a, First Python code\n", |
111 | 129 | "Compute the value of the polynomial $y=ax^2+bx+c$ at $x=-2$, $x=0$, and $x=2.1$ using $a=1$, $b=1$, $c=-6$ and print the results to the screen." |
|
120 | 138 | }, |
121 | 139 | { |
122 | 140 | "cell_type": "markdown", |
123 | | - "metadata": {}, |
| 141 | + "metadata": { |
| 142 | + "editable": true, |
| 143 | + "slideshow": { |
| 144 | + "slide_type": "" |
| 145 | + }, |
| 146 | + "tags": [] |
| 147 | + }, |
124 | 148 | "source": [ |
125 | 149 | "<a href=\"#ex1aanswer\">Answer to Exercise 1a</a>" |
126 | 150 | ] |
|
181 | 205 | }, |
182 | 206 | { |
183 | 207 | "cell_type": "markdown", |
184 | | - "metadata": {}, |
| 208 | + "metadata": { |
| 209 | + "editable": true, |
| 210 | + "slideshow": { |
| 211 | + "slide_type": "" |
| 212 | + }, |
| 213 | + "tags": [] |
| 214 | + }, |
185 | 215 | "source": [ |
186 | 216 | "### <a id=\"ex1b\"></a> Exercise 1b, First Python code using f-strings\n", |
187 | 217 | "Compute the value of the polynomial $y=ax^2+bx+c$ at $x=-2$, $x=0$, and $x=2.1$ using $a=1$, $b=1$, $c=-6$ and print the results to the screen using f-strings and 2 decimal places." |
|
196 | 226 | }, |
197 | 227 | { |
198 | 228 | "cell_type": "markdown", |
199 | | - "metadata": {}, |
| 229 | + "metadata": { |
| 230 | + "editable": true, |
| 231 | + "slideshow": { |
| 232 | + "slide_type": "" |
| 233 | + }, |
| 234 | + "tags": [] |
| 235 | + }, |
200 | 236 | "source": [ |
201 | 237 | "<a href=\"#ex1banswer\">Answer to Exercise 1b</a>" |
202 | 238 | ] |
203 | 239 | }, |
204 | 240 | { |
205 | 241 | "cell_type": "markdown", |
206 | | - "metadata": {}, |
| 242 | + "metadata": { |
| 243 | + "editable": true, |
| 244 | + "slideshow": { |
| 245 | + "slide_type": "" |
| 246 | + }, |
| 247 | + "tags": [] |
| 248 | + }, |
207 | 249 | "source": [ |
208 | 250 | "### More on variables\n", |
209 | 251 | "Once you have created a variable in a Python session, it will remain in memory, so you can use it in other cells as well. For example, the variables `a` and `b`, which were defined two code cells above in this Notebook, still exist. " |
|
401 | 443 | }, |
402 | 444 | { |
403 | 445 | "cell_type": "markdown", |
404 | | - "metadata": {}, |
| 446 | + "metadata": { |
| 447 | + "editable": true, |
| 448 | + "slideshow": { |
| 449 | + "slide_type": "" |
| 450 | + }, |
| 451 | + "tags": [] |
| 452 | + }, |
405 | 453 | "source": [ |
406 | 454 | "### <a id=\"ex2\"></a> Exercise 2, First graph\n", |
407 | 455 | "Plot $y=(x+2)(x-1)(x-2)$ for $x$ going from $-3$ to $+3$ using a dashed red line. On the same figure, plot a blue circle for every point where $y$ equals zero. Set the size of the markers to 10 (you may need to read the help of `plt.plot` to find out how to do that). Label the axes as 'x-axis' and 'y-axis'. Add the title 'First nice Python figure of Your Name', where you enter your own name." |
|
410 | 458 | { |
411 | 459 | "cell_type": "code", |
412 | 460 | "execution_count": null, |
413 | | - "metadata": {}, |
| 461 | + "metadata": { |
| 462 | + "editable": true, |
| 463 | + "slideshow": { |
| 464 | + "slide_type": "" |
| 465 | + }, |
| 466 | + "tags": [] |
| 467 | + }, |
414 | 468 | "outputs": [], |
415 | 469 | "source": [] |
416 | 470 | }, |
417 | 471 | { |
418 | 472 | "cell_type": "markdown", |
419 | | - "metadata": {}, |
| 473 | + "metadata": { |
| 474 | + "editable": true, |
| 475 | + "slideshow": { |
| 476 | + "slide_type": "" |
| 477 | + }, |
| 478 | + "tags": [] |
| 479 | + }, |
420 | 480 | "source": [ |
421 | 481 | "<a href=\"#ex2answer\">Answer to Exercise 2</a>" |
422 | 482 | ] |
423 | 483 | }, |
424 | 484 | { |
425 | 485 | "cell_type": "markdown", |
426 | | - "metadata": {}, |
| 486 | + "metadata": { |
| 487 | + "editable": true, |
| 488 | + "slideshow": { |
| 489 | + "slide_type": "" |
| 490 | + }, |
| 491 | + "tags": [] |
| 492 | + }, |
427 | 493 | "source": [ |
428 | 494 | "### Style\n", |
429 | 495 | "\n", |
|
500 | 566 | }, |
501 | 567 | { |
502 | 568 | "cell_type": "markdown", |
503 | | - "metadata": {}, |
| 569 | + "metadata": { |
| 570 | + "editable": true, |
| 571 | + "slideshow": { |
| 572 | + "slide_type": "" |
| 573 | + }, |
| 574 | + "tags": [] |
| 575 | + }, |
504 | 576 | "source": [ |
505 | 577 | "### <a id=\"ex3\"></a> Exercise 3, Loading data and adding a legend\n", |
506 | 578 | "You are provided with the data files containing the mean montly temperature of Holland, New York City, and Beijing. The Dutch data is stored in `holland_temperature.dat`, and the other filenames are similar. Plot the temperature for each location against the number of the month (starting with 1 for January) all in a single graph. Add a legend by using the function `plt.legend(['line1','line2'])`, etc., but then with more descriptive names. Find out about the `legend` command using `plt.legend?`. Place the legend in an appropriate spot (the upper left-hand corner may be nice, or let Python figure out the best place). " |
|
515 | 587 | }, |
516 | 588 | { |
517 | 589 | "cell_type": "markdown", |
518 | | - "metadata": {}, |
| 590 | + "metadata": { |
| 591 | + "editable": true, |
| 592 | + "slideshow": { |
| 593 | + "slide_type": "" |
| 594 | + }, |
| 595 | + "tags": [] |
| 596 | + }, |
519 | 597 | "source": [ |
520 | 598 | "<a href=\"#ex3answer\">Answer to Exercise 3</a>" |
521 | 599 | ] |
522 | 600 | }, |
523 | 601 | { |
524 | 602 | "cell_type": "markdown", |
525 | | - "metadata": {}, |
| 603 | + "metadata": { |
| 604 | + "editable": true, |
| 605 | + "slideshow": { |
| 606 | + "slide_type": "" |
| 607 | + }, |
| 608 | + "tags": [] |
| 609 | + }, |
526 | 610 | "source": [ |
527 | 611 | "### <a id=\"ex4\"></a> Exercise 4, Subplots and fancy tick markers\n", |
528 | 612 | "Load the average monthly air temperature and seawater temperature for Holland. Create one plot with two graphs above each other using the `subplot` command (use `plt.subplot?` to find out how). On the top graph, plot the air and sea temperature. Label the ticks on the horizontal axis as 'jan', 'feb', 'mar', etc., rather than numbers. Use `plt.xticks?` to find out how. In the bottom graph, plot the difference between the air and seawater temperature. Add legends, axes labels, the whole shebang." |
|
537 | 621 | }, |
538 | 622 | { |
539 | 623 | "cell_type": "markdown", |
540 | | - "metadata": {}, |
| 624 | + "metadata": { |
| 625 | + "editable": true, |
| 626 | + "slideshow": { |
| 627 | + "slide_type": "" |
| 628 | + }, |
| 629 | + "tags": [] |
| 630 | + }, |
541 | 631 | "source": [ |
542 | 632 | "<a href=\"#ex4answer\">Answer to Exercise 4</a>" |
543 | 633 | ] |
|
611 | 701 | }, |
612 | 702 | { |
613 | 703 | "cell_type": "markdown", |
614 | | - "metadata": {}, |
| 704 | + "metadata": { |
| 705 | + "editable": true, |
| 706 | + "slideshow": { |
| 707 | + "slide_type": "" |
| 708 | + }, |
| 709 | + "tags": [] |
| 710 | + }, |
615 | 711 | "source": [ |
616 | 712 | "### <a id=\"ex5\"></a> Exercise 5, Pie Chart\n", |
617 | 713 | "At the 2012 London Olympics, the top ten countries (plus the rest) receiving gold medals were `['USA', 'CHN', 'GBR', 'RUS', 'KOR', 'GER', 'FRA', 'ITA', 'HUN', 'AUS', 'OTHER']`. They received `[46, 38, 29, 24, 13, 11, 11, 8, 8, 7, 107]` gold medals, respectively. Make a pie chart (use `plt.pie?` or go to the pie charts in the matplotlib gallery) of the top 10 gold medal winners plus the others at the London Olympics. Try some of the keyword arguments to make the plot look nice. You may want to give the command `plt.axis('equal')` to make the scales along the horizontal and vertical axes equal so that the pie actually looks like a circle rather than an ellipse. Use the `colors` keyword in your pie chart to specify a sequence of colors. The sequence must be between square brackets, each color must be between quotes preserving upper and lower cases, and they must be separated by comma's like `['MediumBlue','SpringGreen','BlueViolet']`; the sequence is repeated if it is not long enough." |
|
689 | 785 | }, |
690 | 786 | { |
691 | 787 | "cell_type": "markdown", |
692 | | - "metadata": {}, |
| 788 | + "metadata": { |
| 789 | + "editable": true, |
| 790 | + "slideshow": { |
| 791 | + "slide_type": "" |
| 792 | + }, |
| 793 | + "tags": [] |
| 794 | + }, |
693 | 795 | "source": [ |
694 | 796 | "<a href=\"#ex1a\">Back to Exercise 1a</a>\n", |
695 | 797 | "\n", |
|
718 | 820 | }, |
719 | 821 | { |
720 | 822 | "cell_type": "markdown", |
721 | | - "metadata": {}, |
| 823 | + "metadata": { |
| 824 | + "editable": true, |
| 825 | + "slideshow": { |
| 826 | + "slide_type": "" |
| 827 | + }, |
| 828 | + "tags": [] |
| 829 | + }, |
722 | 830 | "source": [ |
723 | 831 | "<a href=\"#ex1b\">Back to Exercise 1b</a>\n", |
724 | 832 | "\n", |
|
742 | 850 | }, |
743 | 851 | { |
744 | 852 | "cell_type": "markdown", |
745 | | - "metadata": {}, |
| 853 | + "metadata": { |
| 854 | + "editable": true, |
| 855 | + "slideshow": { |
| 856 | + "slide_type": "" |
| 857 | + }, |
| 858 | + "tags": [] |
| 859 | + }, |
746 | 860 | "source": [ |
747 | 861 | "<a href=\"#ex2\">Back to Exercise 2</a>\n", |
748 | 862 | "\n", |
|
769 | 883 | }, |
770 | 884 | { |
771 | 885 | "cell_type": "markdown", |
772 | | - "metadata": {}, |
| 886 | + "metadata": { |
| 887 | + "editable": true, |
| 888 | + "slideshow": { |
| 889 | + "slide_type": "" |
| 890 | + }, |
| 891 | + "tags": [] |
| 892 | + }, |
773 | 893 | "source": [ |
774 | 894 | "<a href=\"#ex3\">Back to Exercise 3</a>\n", |
775 | 895 | "\n", |
|
801 | 921 | }, |
802 | 922 | { |
803 | 923 | "cell_type": "markdown", |
804 | | - "metadata": {}, |
| 924 | + "metadata": { |
| 925 | + "editable": true, |
| 926 | + "slideshow": { |
| 927 | + "slide_type": "" |
| 928 | + }, |
| 929 | + "tags": [] |
| 930 | + }, |
805 | 931 | "source": [ |
806 | 932 | "<a href=\"#ex4\">Back to Exercise 4</a>\n", |
807 | 933 | "\n", |
|
822 | 948 | }, |
823 | 949 | { |
824 | 950 | "cell_type": "markdown", |
825 | | - "metadata": {}, |
| 951 | + "metadata": { |
| 952 | + "editable": true, |
| 953 | + "slideshow": { |
| 954 | + "slide_type": "" |
| 955 | + }, |
| 956 | + "tags": [] |
| 957 | + }, |
826 | 958 | "source": [ |
827 | 959 | "<a href=\"#ex5\">Back to Exercise 5</a>\n", |
828 | 960 | "\n", |
|
847 | 979 | }, |
848 | 980 | { |
849 | 981 | "cell_type": "markdown", |
850 | | - "metadata": {}, |
| 982 | + "metadata": { |
| 983 | + "editable": true, |
| 984 | + "slideshow": { |
| 985 | + "slide_type": "" |
| 986 | + }, |
| 987 | + "tags": [] |
| 988 | + }, |
851 | 989 | "source": [ |
852 | 990 | "<a href=\"#ex6\">Back to Exercise 6</a>" |
853 | 991 | ] |
854 | 992 | }, |
855 | 993 | { |
856 | 994 | "cell_type": "markdown", |
857 | | - "metadata": {}, |
| 995 | + "metadata": { |
| 996 | + "editable": true, |
| 997 | + "slideshow": { |
| 998 | + "slide_type": "" |
| 999 | + }, |
| 1000 | + "tags": [] |
| 1001 | + }, |
858 | 1002 | "source": [] |
859 | 1003 | } |
860 | 1004 | ], |
|
875 | 1019 | "name": "python", |
876 | 1020 | "nbconvert_exporter": "python", |
877 | 1021 | "pygments_lexer": "ipython3", |
878 | | - "version": "3.13.5" |
| 1022 | + "version": "3.13.7" |
879 | 1023 | }, |
880 | 1024 | "latex_envs": { |
881 | 1025 | "LaTeX_envs_menu_present": true, |
|
0 commit comments