|
40 | 40 | "if 'google.colab' in sys.modules:\n", |
41 | 41 | " get_ipython().events.register('pre_run_cell', enable_plotly_in_cell)\n", |
42 | 42 | " !mkdir -p data\n", |
43 | | - " !wget -P data https://raw.githubusercontent.com/ualberta-rcg/python-plotting/master/notebooks/data/gapminder_gdp_europe.csv" |
| 43 | + " !wget -P data https://raw.githubusercontent.com/ualberta-rcg/python-plotting/master/notebooks/data/gapminder_gdp_europe.csv\n", |
| 44 | + " !mkdir -p solutions\n", |
| 45 | + " !wget -P solutions https://github.com/ualberta-rcg/python-plotting/blob/master/notebooks/solutions/plotly-bar-chart-north-america.py" |
44 | 46 | ] |
45 | 47 | }, |
46 | 48 | { |
|
161 | 163 | "fig = go.Figure(data=data, layout=layout)\n", |
162 | 164 | "py.iplot(fig)" |
163 | 165 | ] |
| 166 | + }, |
| 167 | + { |
| 168 | + "cell_type": "markdown", |
| 169 | + "metadata": {}, |
| 170 | + "source": [ |
| 171 | + "## Exercise" |
| 172 | + ] |
| 173 | + }, |
| 174 | + { |
| 175 | + "cell_type": "markdown", |
| 176 | + "metadata": {}, |
| 177 | + "source": [ |
| 178 | + "Let's grab some North American GDP data (code to download below).\n", |
| 179 | + "\n", |
| 180 | + "Using what you learned here and in the scatter plot section, do the following:\n", |
| 181 | + "\n", |
| 182 | + "* Using this data set, make a bar chart of the per-capita GDP growth of Canada, the United States, and Mexico.\n", |
| 183 | + "* Label the chart \"Per-capita GDP Growth in North America\".\n", |
| 184 | + "* Make the Canada bar red, the US bar blue, and the Mexico bar green. **Hint!** Check the documentation on how to set the color of the bars: https://plot.ly/python/bar-charts/\n", |
| 185 | + "* Label the axes!" |
| 186 | + ] |
| 187 | + }, |
| 188 | + { |
| 189 | + "cell_type": "code", |
| 190 | + "execution_count": null, |
| 191 | + "metadata": {}, |
| 192 | + "outputs": [], |
| 193 | + "source": [ |
| 194 | + "# Grabbing the data:\n", |
| 195 | + "!mkdir -p data\n", |
| 196 | + "!wget -P data https://raw.githubusercontent.com/ualberta-rcg/python-intro/gh-pages/data/gapminder_gdp_americas.csv" |
| 197 | + ] |
| 198 | + }, |
| 199 | + { |
| 200 | + "cell_type": "code", |
| 201 | + "execution_count": null, |
| 202 | + "metadata": {}, |
| 203 | + "outputs": [], |
| 204 | + "source": [ |
| 205 | + "df = pd.read_csv('data/gapminder_gdp_americas.csv', index_col='country')\n", |
| 206 | + "df = df.drop(columns=['continent'])\n", |
| 207 | + "years = df.columns.str.strip('gdpPercap_')\n", |
| 208 | + "df.columns = years.astype(int)\n", |
| 209 | + "\n", |
| 210 | + "# Your code goes here ..." |
| 211 | + ] |
| 212 | + }, |
| 213 | + { |
| 214 | + "cell_type": "code", |
| 215 | + "execution_count": null, |
| 216 | + "metadata": {}, |
| 217 | + "outputs": [], |
| 218 | + "source": [ |
| 219 | + "%load solutions/plotly-bar-chart-north-america.py\n", |
| 220 | + "\n", |
| 221 | + "# SOLUTION\n", |
| 222 | + "# Run this cell once to load the solution\n", |
| 223 | + "# Run this cell a second time to actually run the code" |
| 224 | + ] |
164 | 225 | } |
165 | 226 | ], |
166 | 227 | "metadata": { |
|
0 commit comments