Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 683966c

Browse files
authored
Update Chapter 1
1 parent 7758555 commit 683966c

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

Chapter 1

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,33 @@ plt.xticks(tick_val,tick_lab)
2727

2828
# After customizing, display the plot
2929
plt.show()
30+
31+
Sizes
32+
Right now, the scatter plot is just a cloud of blue dots, indistinguishable from each other. Let's change this. Wouldn't it be nice if the size of the dots corresponds to the population?
33+
34+
To accomplish this, there is a list pop loaded in your workspace. It contains population numbers for each country expressed in millions. You can see that this list is added to the scatter method, as the argument s, for size.
35+
36+
# Import numpy as np
37+
import numpy as np
38+
39+
# Store pop as a numpy array: np_pop
40+
np_pop=np.array(pop)
41+
42+
# Double np_pop
43+
np_pop = np_pop * 2
44+
45+
# Update: set s argument to np_pop
46+
plt.scatter(gdp_cap, life_exp, s = np_pop)
47+
48+
# Previous customizations
49+
plt.xscale('log')
50+
plt.xlabel('GDP per Capita [in USD]')
51+
plt.ylabel('Life Expectancy [in years]')
52+
plt.title('World Development in 2007')
53+
plt.xticks([1000, 10000, 100000],['1k', '10k', '100k'])
54+
55+
# Display the plot
56+
plt.show()
57+
58+
59+

0 commit comments

Comments
 (0)