-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
59 lines (45 loc) · 1.45 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
gapminder = pd.read_csv('datasets/gapminder.csv')
gdp_cap = gapminder['gdp_cap'].to_list()
life_exp = gapminder['life_exp'].to_list()
np_population = gapminder['population'].to_numpy()
# Express population in millions and then double the values for plot impact
np_population = np_population / 1000000
np_population = np_population * 2
continent_colour = {
'Asia': 'red',
'Europe': 'blue',
'Africa': 'black',
'Americas': 'green',
'Oceania': 'yellow',
}
# Use the dictionary to map continent to a specific colour
country_colour = gapminder['cont'].map(continent_colour).to_list()
# Basic scatter plot, log scale; s is a size argument for the scatter plot
plt.scatter(gdp_cap, life_exp, s = np_population, c = country_colour, alpha = 0.8)
plt.xscale('log')
# Strings
xlab = 'GDP per Capita [in USD]'
ylab = 'Life Expectancy [in years]'
title = 'World Development in 2007'
# Add axis labels
plt.xlabel(xlab)
plt.ylabel(ylab)
# Add title
plt.title(title)
# Definition of tick_val and tick_lab
tick_val = [1000, 10000, 100000]
tick_lab = ['1k', '10k', '100k']
# Adapt the ticks on the x-axis
plt.xticks(tick_val, tick_lab)
# Additional customizations
plt.text(12800, 75, 'Argentina', weight="bold")
plt.text(5000, 73, 'China', weight="bold")
plt.text(2450, 65, 'India', weight="bold")
plt.text(43000, 78, 'USA', weight="bold")
# Add grid() call
plt.grid(True)
# Show the plot
plt.show()