|
55 | 55 | "\n", |
56 | 56 | "You can do this by shifting the x-coordinates of your bars, and setting the bar width using the `width=` argument to the bar graph function.\n", |
57 | 57 | "\n", |
58 | | - "* copy your plotting code from the last notebook. \n", |
59 | | - "* make a numpy array of the month list.\n", |
60 | | - "* now you can easily add or subtract a number from the whole array.\n", |
61 | | - "* make a plot where the bars for the different regions don't overlap.\n", |
| 58 | + "Let's see how it works...\n", |
| 59 | + "\n", |
| 60 | + "* first copy your plotting code from the last exercise notebook. \n", |
| 61 | + "* use the `width=` argument of the <code>plt.bar</code> function to change the width of the bars.\n", |
| 62 | + "* now make a numpy array of the month list.\n", |
| 63 | + "* now you can easily add or subtract a single number from this array, and in this way you can shift the x-values for the different countries a little to the left or right when plotting the bars for that country.\n", |
| 64 | + "\n", |
| 65 | + "Try out: make a plot where the bars for the different regions don't overlap.\n", |
62 | 66 | "\n", |
63 | 67 | "</div></div>" |
64 | 68 | ] |
|
78 | 82 | "source": [ |
79 | 83 | "<div class=\"alert alert-block alert-info\"><b>Exercise 6.3</b><br><br><div style=\"text-align: justify\">\n", |
80 | 84 | "\n", |
81 | | - "* Create a 4x2 matrix `m` filled with different values \n", |
| 85 | + "In linear algebra you will learn about matrices, which are basically 2D arrays (a vector being the 1D equivalent): an $m\\times n$ matrix has $m$ rows and $n$ columns.\n", |
82 | 86 | "\n", |
83 | | - "4x2 means four rows and two columns.\n", |
84 | | - "You can use `np.array()`, and pass it nested lists,\n", |
85 | | - "or you can use `np.zeros((rows, columns))` and fill in the values afterwards.\n", |
86 | | - "Here `rows` and `columns` are the number of rows and columns you want. Note the double parentheses. The reason is that `(rows, columns)` is a tuple,\n", |
87 | | - "and the `np.zeros()` function takes this tuple as it's argument.\n", |
| 87 | + "* Create a 4x2 matrix `M` filled with different values you may choose yourself\n", |
88 | 88 | "\n", |
| 89 | + "You can use `np.array()`, and pass it nested lists (lists within a list),\n", |
| 90 | + "or you can use `M = np.zeros((rows, columns))` and fill in the values afterwards by assigning values to the individual elements.\n", |
| 91 | + "Here `rows` and `columns` are the number of rows and columns you want. Note the double parentheses. The reason is that `(rows, columns)` is a tuple, and the `np.zeros()` function takes this tuple as it's argument to create a matrix filled with zeros of the required dimensions.\n", |
89 | 92 | "\n", |
90 | | - "* Print the shape of your matrix.\n", |
| 93 | + "* Check the shape of your matrix, using `M.shape`\n", |
91 | 94 | "\n", |
92 | | - "* Try the `transpose()` function on your array (hint: `m.transpose()`). What did it do?\n", |
| 95 | + "* Try the transpose() function on your array (hint: `M.transpose()`). What did it do?\n", |
93 | 96 | "\n", |
94 | 97 | "</div></div>" |
95 | 98 | ] |
|
142 | 145 | "source": [ |
143 | 146 | "<div class=\"alert alert-block alert-info\"><b>Exercise 6.5 Plot the RICO input data</b><br><br><div style=\"text-align: justify\">\n", |
144 | 147 | "\n", |
145 | | - "* split the matrix into separate variables for each column \n", |
| 148 | + "* load the data\n", |
| 149 | + "* create a separate array (with their own name) for each column \n", |
146 | 150 | "* use subplots to plot several quantities side by side:\n", |
147 | 151 | " ```\n", |
148 | 152 | " fig, axes = plt.subplots(nrows=1, ncols=5, sharey=True, figsize=(13,4))\n", |
149 | 153 | " ```\n", |
| 154 | + "* `figsize=(13,4)` to set the figure size in inches (width, height) at some assumed dots-per-inch value. It's included here to make the plot a bit wider, so that the labels don't overlap. Change the values a bit to see what happens.\n", |
150 | 155 | "* to plot in the first subplot, use `axes[0].plot(...)`\n", |
151 | 156 | "* to set x and y labels, use `axes[0].set_ylabel(...)`\n", |
152 | | - "* use the y axis of the plot for the hight above ground\n", |
153 | | - " \n", |
154 | | - " \n", |
155 | | - "* `sharey=True` makes the plots share the y axis\n", |
156 | | - "* `figsize=(13,4)` sets the figure size in inches (width, height) at some assumed dots-per-inch value. It's included here to make the plot a bit wider, so that the labels don't overlap. \n", |
| 157 | + "* use the y-axis of the plot for the height above ground, in this way it is the same for all subplots \n", |
| 158 | + "* ... and that's why we used `sharey=True` we tell matplotlib that the y-axis is to be shared\n", |
| 159 | + "\n", |
157 | 160 | "\n", |
158 | 161 | "</div></div>" |
159 | 162 | ] |
|
170 | 173 | ], |
171 | 174 | "metadata": { |
172 | 175 | "kernelspec": { |
173 | | - "display_name": "Python 3 (ipykernel)", |
| 176 | + "display_name": "base", |
174 | 177 | "language": "python", |
175 | 178 | "name": "python3" |
176 | 179 | }, |
|
184 | 187 | "name": "python", |
185 | 188 | "nbconvert_exporter": "python", |
186 | 189 | "pygments_lexer": "ipython3", |
187 | | - "version": "3.10.0" |
| 190 | + "version": "3.13.2" |
188 | 191 | }, |
189 | 192 | "latex_envs": { |
190 | 193 | "LaTeX_envs_menu_present": true, |
|
203 | 206 | "latex_user_defs": false, |
204 | 207 | "report_style_numbering": false, |
205 | 208 | "user_envs_cfg": false |
206 | | - }, |
207 | | - "vscode": { |
208 | | - "interpreter": { |
209 | | - "hash": "1fe2f2b718b1108b9c4176932db8a0ead471245140baaa21ea96a4066683e6b2" |
210 | | - } |
211 | 209 | } |
212 | 210 | }, |
213 | 211 | "nbformat": 4, |
|
0 commit comments