|
209 | 209 | "\n", |
210 | 210 | "- A module `plotting.py` containing all code responsible for plotting of results. \n", |
211 | 211 | "\n", |
212 | | - "- A script file `run.py` that imports the modules and is used to run the code. \n", |
| 212 | + "- A script file `main.py` that imports the modules and is used to run the code. \n", |
213 | 213 | "\n", |
214 | 214 | "---\n", |
215 | 215 | "```python\n", |
216 | | - "# run.py\n", |
| 216 | + "# main.py\n", |
217 | 217 | "\n", |
218 | 218 | "import utils\n", |
219 | 219 | "import plotting\n", |
|
238 | 238 | "\n", |
239 | 239 | "- encourages the creator to make the code in `utils` and `plotting` more project independent\n", |
240 | 240 | "\n", |
241 | | - "- makes the actual *working file* (`run.py`) more clean since most of the complicated logic sits inside separate modules\n", |
| 241 | + "- makes the actual *working file* (`main.py`) more clean since most of the complicated logic sits inside separate modules\n", |
242 | 242 | "\n", |
243 | 243 | "A more [here](https://chrisyeh96.github.io/2017/08/08/definitive-guide-python-imports.html) for a good resource on Python import statements." |
244 | 244 | ] |
|
314 | 314 | }, |
315 | 315 | { |
316 | 316 | "cell_type": "code", |
317 | | - "execution_count": 18, |
| 317 | + "execution_count": 2, |
318 | 318 | "metadata": {}, |
319 | 319 | "outputs": [ |
320 | 320 | { |
|
337 | 337 | }, |
338 | 338 | { |
339 | 339 | "cell_type": "code", |
340 | | - "execution_count": 19, |
| 340 | + "execution_count": 3, |
341 | 341 | "metadata": {}, |
342 | 342 | "outputs": [ |
343 | 343 | { |
|
347 | 347 | "traceback": [ |
348 | 348 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", |
349 | 349 | "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", |
350 | | - "\u001b[1;32m<ipython-input-19-6951c56cbd33>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[1;31m# Run the function with an argument when it expects no arguments\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[0mstandard_func\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'Hi'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m'Ho'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", |
| 350 | + "\u001b[1;32m<ipython-input-3-5340979a5eb5>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[1;31m# Run the function with two arguments when it expects only a single argument\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[0mstandard_func\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'Hi'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m'Ho'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", |
351 | 351 | "\u001b[1;31mTypeError\u001b[0m: standard_func() takes 1 positional argument but 2 were given" |
352 | 352 | ] |
353 | 353 | } |
|
370 | 370 | }, |
371 | 371 | { |
372 | 372 | "cell_type": "code", |
373 | | - "execution_count": 22, |
| 373 | + "execution_count": 4, |
374 | 374 | "metadata": {}, |
375 | 375 | "outputs": [ |
376 | 376 | { |
|
439 | 439 | }, |
440 | 440 | { |
441 | 441 | "cell_type": "code", |
442 | | - "execution_count": 23, |
| 442 | + "execution_count": 6, |
443 | 443 | "metadata": {}, |
444 | 444 | "outputs": [ |
445 | 445 | { |
|
459 | 459 | }, |
460 | 460 | { |
461 | 461 | "cell_type": "code", |
462 | | - "execution_count": 24, |
| 462 | + "execution_count": 7, |
463 | 463 | "metadata": {}, |
464 | 464 | "outputs": [ |
465 | 465 | { |
|
490 | 490 | }, |
491 | 491 | { |
492 | 492 | "cell_type": "code", |
493 | | - "execution_count": 6, |
| 493 | + "execution_count": 8, |
494 | 494 | "metadata": {}, |
495 | 495 | "outputs": [ |
496 | 496 | { |
|
546 | 546 | }, |
547 | 547 | { |
548 | 548 | "cell_type": "code", |
549 | | - "execution_count": 7, |
| 549 | + "execution_count": 9, |
550 | 550 | "metadata": {}, |
551 | 551 | "outputs": [ |
552 | 552 | { |
|
555 | 555 | "array([-2. , -1.5, -1. , -0.5, 0. , 0.5, 1. , 1.5])" |
556 | 556 | ] |
557 | 557 | }, |
558 | | - "execution_count": 7, |
| 558 | + "execution_count": 9, |
559 | 559 | "metadata": {}, |
560 | 560 | "output_type": "execute_result" |
561 | 561 | } |
|
592 | 592 | }, |
593 | 593 | { |
594 | 594 | "cell_type": "code", |
595 | | - "execution_count": 8, |
| 595 | + "execution_count": 10, |
596 | 596 | "metadata": {}, |
597 | 597 | "outputs": [ |
598 | 598 | { |
|
601 | 601 | "array([ True, True, True, True, True, False, False, False])" |
602 | 602 | ] |
603 | 603 | }, |
604 | | - "execution_count": 8, |
| 604 | + "execution_count": 10, |
605 | 605 | "metadata": {}, |
606 | 606 | "output_type": "execute_result" |
607 | 607 | } |
|
622 | 622 | }, |
623 | 623 | { |
624 | 624 | "cell_type": "code", |
625 | | - "execution_count": 9, |
| 625 | + "execution_count": 11, |
626 | 626 | "metadata": {}, |
627 | 627 | "outputs": [ |
628 | 628 | { |
|
631 | 631 | "array([False, False, True, True, True, True, True, False])" |
632 | 632 | ] |
633 | 633 | }, |
634 | | - "execution_count": 9, |
| 634 | + "execution_count": 11, |
635 | 635 | "metadata": {}, |
636 | 636 | "output_type": "execute_result" |
637 | 637 | } |
|
652 | 652 | }, |
653 | 653 | { |
654 | 654 | "cell_type": "code", |
655 | | - "execution_count": 10, |
| 655 | + "execution_count": 12, |
656 | 656 | "metadata": {}, |
657 | 657 | "outputs": [ |
658 | 658 | { |
|
661 | 661 | "(array([0, 1, 2, 3, 4], dtype=int64),)" |
662 | 662 | ] |
663 | 663 | }, |
664 | | - "execution_count": 10, |
| 664 | + "execution_count": 12, |
665 | 665 | "metadata": {}, |
666 | 666 | "output_type": "execute_result" |
667 | 667 | } |
|
673 | 673 | }, |
674 | 674 | { |
675 | 675 | "cell_type": "code", |
676 | | - "execution_count": 11, |
| 676 | + "execution_count": 13, |
677 | 677 | "metadata": {}, |
678 | 678 | "outputs": [ |
679 | 679 | { |
|
682 | 682 | "(array([2, 3, 4, 5, 6], dtype=int64),)" |
683 | 683 | ] |
684 | 684 | }, |
685 | | - "execution_count": 11, |
| 685 | + "execution_count": 13, |
686 | 686 | "metadata": {}, |
687 | 687 | "output_type": "execute_result" |
688 | 688 | } |
|
717 | 717 | }, |
718 | 718 | { |
719 | 719 | "cell_type": "code", |
720 | | - "execution_count": 12, |
| 720 | + "execution_count": 14, |
721 | 721 | "metadata": {}, |
722 | 722 | "outputs": [ |
723 | 723 | { |
|
726 | 726 | "array([ 1, 2, 3, 11, 12])" |
727 | 727 | ] |
728 | 728 | }, |
729 | | - "execution_count": 12, |
| 729 | + "execution_count": 14, |
730 | 730 | "metadata": {}, |
731 | 731 | "output_type": "execute_result" |
732 | 732 | } |
|
758 | 758 | }, |
759 | 759 | { |
760 | 760 | "cell_type": "code", |
761 | | - "execution_count": 13, |
| 761 | + "execution_count": 15, |
762 | 762 | "metadata": {}, |
763 | 763 | "outputs": [ |
764 | 764 | { |
|
767 | 767 | "array([-2. , -1.5, -1. , -0.5, 0. , 0.5, 1. , 1.5])" |
768 | 768 | ] |
769 | 769 | }, |
770 | | - "execution_count": 13, |
| 770 | + "execution_count": 15, |
771 | 771 | "metadata": {}, |
772 | 772 | "output_type": "execute_result" |
773 | 773 | } |
|
779 | 779 | }, |
780 | 780 | { |
781 | 781 | "cell_type": "code", |
782 | | - "execution_count": 14, |
| 782 | + "execution_count": 16, |
783 | 783 | "metadata": {}, |
784 | 784 | "outputs": [ |
785 | 785 | { |
|
788 | 788 | "array([3, 4])" |
789 | 789 | ] |
790 | 790 | }, |
791 | | - "execution_count": 14, |
| 791 | + "execution_count": 16, |
792 | 792 | "metadata": {}, |
793 | 793 | "output_type": "execute_result" |
794 | 794 | } |
|
801 | 801 | }, |
802 | 802 | { |
803 | 803 | "cell_type": "code", |
804 | | - "execution_count": 15, |
| 804 | + "execution_count": 17, |
805 | 805 | "metadata": {}, |
806 | 806 | "outputs": [ |
807 | 807 | { |
|
810 | 810 | "array([-0.5, 0. ])" |
811 | 811 | ] |
812 | 812 | }, |
813 | | - "execution_count": 15, |
| 813 | + "execution_count": 17, |
814 | 814 | "metadata": {}, |
815 | 815 | "output_type": "execute_result" |
816 | 816 | } |
|
924 | 924 | " -------\n", |
925 | 925 | " 1D numpy array\n", |
926 | 926 | " Array of indices for `x`-values that reside within `x_bounds`.\n", |
927 | | - "'''\n", |
| 927 | + " \n", |
| 928 | + " Assumptions\n", |
| 929 | + " ------------\n", |
| 930 | + " The function assumes that the input array `x` is sorted in\n", |
| 931 | + " ascending order.\n", |
| 932 | + " '''\n", |
928 | 933 | " # Your code here!\n", |
929 | 934 | "```\n", |
930 | 935 | "---\n", |
|
1033 | 1038 | }, |
1034 | 1039 | { |
1035 | 1040 | "cell_type": "code", |
1036 | | - "execution_count": 16, |
| 1041 | + "execution_count": 18, |
1037 | 1042 | "metadata": {}, |
1038 | 1043 | "outputs": [ |
1039 | 1044 | { |
|
1042 | 1047 | "{'2*0': 0, '2*1': 2, '2*2': 4, '2*3': 6, '2*4': 8}" |
1043 | 1048 | ] |
1044 | 1049 | }, |
1045 | | - "execution_count": 16, |
| 1050 | + "execution_count": 18, |
1046 | 1051 | "metadata": {}, |
1047 | 1052 | "output_type": "execute_result" |
1048 | 1053 | } |
|
1073 | 1078 | "\n", |
1074 | 1079 | "---\n", |
1075 | 1080 | "```python\n", |
1076 | | - "def annotate_points(points_to_annotate, **kwargs):\n", |
| 1081 | + "def annotate_points(points_to_annotate, ax, **kwargs):\n", |
1077 | 1082 | " '''\n", |
1078 | 1083 | " Annotate points with corresponding text.\n", |
1079 | 1084 | " \n", |
|
1082 | 1087 | " points_to_annoate : dict\n", |
1083 | 1088 | " Dictionary with desired annotation text as keys and the (x, y)-\n", |
1084 | 1089 | " coordinates of the annotation as values.\n", |
| 1090 | + " ax : matplotlib axis object\n", |
| 1091 | + " Axis object on which to plot the annotations. \n", |
1085 | 1092 | " **kwargs : keyword arguments\n", |
1086 | 1093 | " Arguments to be forwarded to the ax.annotate call. \n", |
1087 | 1094 | " '''\n", |
|
1113 | 1120 | "source": [ |
1114 | 1121 | "# Exercise 6\n", |
1115 | 1122 | "\n", |
1116 | | - "Create module `run.py` and import `utils` and `plotting` into it.\n", |
| 1123 | + "Create module `main.py` and import `utils` and `plotting` into it.\n", |
1117 | 1124 | "\n", |
1118 | 1125 | "This is now a \"clean\" file that has access to all of our custom functions without looking cluttered. \n", |
1119 | 1126 | "\n", |
1120 | | - "Set up code that for the graph from the test in Exercise 5 and use the functions previously created to annotate only extreme values within a certain interval of your choice." |
| 1127 | + "Inside `main.py` create a graph and use the functions previously created to annotate only extreme values within a certain $x$-interval of your choice.\n", |
| 1128 | + "\n", |
| 1129 | + "You can use the test code from Exercise 3 and 5 if you want." |
1121 | 1130 | ] |
1122 | 1131 | }, |
1123 | 1132 | { |
|
1133 | 1142 | "\n", |
1134 | 1143 | "- Specify the number of decimal points for the dict keys that are returned from the `arrays_to_dict` function. This would be prettier when the strings that are stored as keys are eventually annotated in the plot. \n", |
1135 | 1144 | "\n", |
1136 | | - "\n", |
1137 | | - "- Add a parameter to `annotate_points` for choosing which axis (plot) to annotate on. The above implementation annotates on the currently active axis. It would be better to have the current axis be the default while making it possible to choose a specific one. \n", |
1138 | | - "\n", |
1139 | 1145 | "If you start altering your existing, working code remember to make sure that you have that code stored in a commit (snapshot). This way you can always revert to that state if need be.\n" |
1140 | 1146 | ] |
1141 | 1147 | }, |
|
1149 | 1155 | }, |
1150 | 1156 | { |
1151 | 1157 | "cell_type": "code", |
1152 | | - "execution_count": 17, |
| 1158 | + "execution_count": 19, |
1153 | 1159 | "metadata": {}, |
1154 | 1160 | "outputs": [ |
1155 | 1161 | { |
|
1422 | 1428 | "<IPython.core.display.HTML object>" |
1423 | 1429 | ] |
1424 | 1430 | }, |
1425 | | - "execution_count": 17, |
| 1431 | + "execution_count": 19, |
1426 | 1432 | "metadata": {}, |
1427 | 1433 | "output_type": "execute_result" |
1428 | 1434 | } |
|
1451 | 1457 | "name": "python", |
1452 | 1458 | "nbconvert_exporter": "python", |
1453 | 1459 | "pygments_lexer": "ipython3", |
1454 | | - "version": "3.7.5" |
| 1460 | + "version": "3.7.4" |
1455 | 1461 | }, |
1456 | 1462 | "latex_envs": { |
1457 | 1463 | "LaTeX_envs_menu_present": true, |
|
0 commit comments