|
38 | 38 | "source": [ |
39 | 39 | "import pandas as pd\n", |
40 | 40 | "pd.options.mode.chained_assignment = None\n", |
41 | | - "import matplotlib.pyplot as plt\n", |
42 | | - "import seaborn as sns\n", |
43 | 41 | "import wbgapi as wb" |
44 | 42 | ] |
45 | 43 | }, |
|
63 | 61 | "- Allows low-level customization of plots\n", |
64 | 62 | "- \"Wordy\" syntax, can get quite complex easily\n", |
65 | 63 | "- Very popular in scientific programming\n", |
| 64 | + "- Ugly aesthetic defaults\n", |
66 | 65 | "\n", |
67 | 66 | "Remember this \"picture\"? it was actually a plot created with `matplotlib`." |
68 | 67 | ] |
|
162 | 161 | "metadata": {}, |
163 | 162 | "outputs": [], |
164 | 163 | "source": [ |
165 | | - "y_data = df[df['Country']=='Mexico']['Population'] / 1000000 # x-axis data: population in millions\n", |
166 | | - "x_data = df[df['Country']=='Mexico']['year'] # y-axis data: years we have data for Mexico" |
| 164 | + "y_data = df[df['Country']=='Mexico']['Population'] / 1000000 # y-axis data: population in millions\n", |
| 165 | + "x_data = df[df['Country']=='Mexico']['year'] # x-axis data: years we have data for Mexico" |
167 | 166 | ] |
168 | 167 | }, |
169 | 168 | { |
|
173 | 172 | "## Using `matplotlib`" |
174 | 173 | ] |
175 | 174 | }, |
| 175 | + { |
| 176 | + "cell_type": "code", |
| 177 | + "execution_count": null, |
| 178 | + "metadata": {}, |
| 179 | + "outputs": [], |
| 180 | + "source": [ |
| 181 | + "import matplotlib.pyplot as plt" |
| 182 | + ] |
| 183 | + }, |
176 | 184 | { |
177 | 185 | "cell_type": "code", |
178 | 186 | "execution_count": null, |
|
232 | 240 | "## Using `seaborn`" |
233 | 241 | ] |
234 | 242 | }, |
| 243 | + { |
| 244 | + "cell_type": "code", |
| 245 | + "execution_count": null, |
| 246 | + "metadata": {}, |
| 247 | + "outputs": [], |
| 248 | + "source": [ |
| 249 | + "import seaborn as sns" |
| 250 | + ] |
| 251 | + }, |
235 | 252 | { |
236 | 253 | "cell_type": "code", |
237 | 254 | "execution_count": null, |
|
275 | 292 | "source": [ |
276 | 293 | "A few details to note:\n", |
277 | 294 | "\n", |
278 | | - "- For this example we defined the x and y-axis data as Pandas series, but they can also be lists (or containers) with numbers or NumPy series\n", |
| 295 | + "- For this example we defined the x and y-axis data as Pandas series, but they can also be lists (or containers) with numbers\n", |
279 | 296 | "- Seaborn accepts two methods to plot visualizations:\n", |
280 | 297 | " + You either pass the x and y-axis data in the arguments `x`, `y`\n", |
281 | | - " + Or you define a Pandas dataframe input in the arugment `data` and set `x` and `y` equal to the column names you take the x-axis and y-axis data from\n", |
| 298 | + " + Or you define a Pandas dataframe input in the argument `data` and set `x` and `y` equal to the column names you take the x-axis and y-axis data from\n", |
282 | 299 | "- Compare the syntax of both libraries to get the same result:\n", |
283 | 300 | "\n", |
284 | 301 | "```\n", |
|
306 | 323 | "# Line plots\n", |
307 | 324 | "\n", |
308 | 325 | "- Line plots have a very similar syntax than bar plots in `matplotlib`, but they use the function `plt.plot()` instead of `plt.barplot()`\n", |
309 | | - "- In `seaborn`, the function is `sns.linelplot()`\n", |
| 326 | + "- In `seaborn`, the function is `sns.lineplot()`\n", |
310 | 327 | "\n", |
311 | 328 | "## `matplotlib`" |
312 | 329 | ] |
|
0 commit comments