@@ -298,12 +298,12 @@ In this exercise we will learn how to use log scales.
298298 ```python
299299 import pandas as pd
300300
301- url = "https://raw.githubusercontent.com/plotly/datasets/master/gapminder_with_codes.csv"
302- data = pd.read_csv(url)
301+ url = (
302+ "https://raw.githubusercontent.com/plotly/datasets/master/gapminder_with_codes.csv"
303+ )
304+ gapminder_data = pd.read_csv(url).query("year == 2007")
303305
304- data_2007 = data[data["year"] == 2007]
305-
306- data_2007
306+ gapminder_data
307307 ```
308308- Try the above snippet in a notebook and it will give you an overview over the data.
309309
@@ -313,10 +313,10 @@ In this exercise we will learn how to use log scales.
313313
314314 fig, ax = plt.subplots()
315315
316- ax.scatter(x=data_2007 ["gdpPercap"], y=data_2007 ["lifeExp"], alpha=0.5)
316+ ax.scatter(x=gapminder_data ["gdpPercap"], y=gapminder_data ["lifeExp"], alpha=0.5)
317317
318- ax.set_xlabel("GDP (USD) per capita")
319- ax.set_ylabel("life expectancy (years)")
318+ ax.set_xlabel("GDP per capita (PPP dollars) ")
319+ ax.set_ylabel("Life expectancy (years)")
320320 ```
321321
322322 This is the result but we realize that a linear scale is not ideal here:
@@ -341,12 +341,12 @@ emphasize-lines: 5
341341---
342342fig, ax = plt.subplots()
343343
344- ax.scatter(x=data_2007 ["gdpPercap"], y=data_2007 ["lifeExp"], alpha=0.5)
344+ ax.scatter(x=gapminder_data ["gdpPercap"], y=gapminder_data ["lifeExp"], alpha=0.5)
345345
346346ax.set_xscale("log")
347347
348- ax.set_xlabel("GDP (USD) per capita")
349- ax.set_ylabel("life expectancy (years)")
348+ ax.set_xlabel("GDP per capita (PPP dollars) ")
349+ ax.set_ylabel("Life expectancy (years)")
350350```
351351* {obj}`alpha <matplotlib.artist.Artist.set_alpha>` sets transparency
352352 of points.
@@ -374,16 +374,17 @@ See {meth}`ax.tick_params <matplotlib.axes.Axes.tick_params>`.
374374
375375```{code-block} python
376376---
377- emphasize-lines: 7-11
377+ emphasize-lines: 7-8, 10-12
378378---
379379fig, ax = plt.subplots()
380380
381- ax.scatter(x=data_2007[ "gdpPercap"] , y=data_2007[ "lifeExp"] , alpha=0.5)
381+ ax.scatter(x="gdpPercap", y="lifeExp", alpha=0.5, data=gapminder_data )
382382
383383ax.set_xscale("log")
384384
385- ax.set_xlabel("GDP (USD) per capita", fontsize=15)
386- ax.set_ylabel("life expectancy (years)", fontsize=15)
385+ ax.set_xlabel("GDP per capita (PPP dollars)", fontsize=15)
386+ ax.set_ylabel("Life expectancy (years)", fontsize=15)
387+
387388ax.tick_params(which="major", length=10)
388389ax.tick_params(which="minor", length=5)
389390ax.tick_params(labelsize=15)
0 commit comments