P3.2.3Annual risk of death statistics
The annual risk of death (given as "1 in N'') for men and women in the UK in 2005 for different age ranges is given in the table below. Use pyplot to plot these data on a single chart.
| Age Range | Female | Male |
|---|---|---|
| < 1 | 227 | 177 |
| 1 - 4 | 5376 | 4386 |
| 5 - 14 | 10417 | 8333 |
| 15 - 24 | 4132 | 1908 |
| 25 - 34 | 2488 | 1215 |
| 35 - 44 | 1106 | 663 |
| 45 - 54 | 421 | 279 |
| 55 - 64 | 178 | 112 |
| 65 - 74 | 65 | 42 |
| 75 - 84 | 21 | 15 |
| > 84 | 7 | 6 |
Show solution
The code below generates a plot of the annual risk of death by age and gender using the provided data.
import numpy as np
import matplotlib.pyplot as plt
# Annual risk of death by age and gender (UK national mortality statistics)
# Risk is 1 in N in age bins given by ages[i-1] - ages[i]
ages = np.array([1, 4, 14, 24, 34, 44, 54, 64, 74, 84, 94])
f_risk = np.array([227, 5376, 10417, 4132, 2488, 1106, 421, 178, 65, 21, 7])
m_risk = np.array([177, 4386, 8333, 1908, 1215, 663, 279, 112, 42, 15, 6])
plt.plot(ages, -np.log10(f_risk), color='m', marker='^',
markeredgecolor='m', markersize=6, label='Female')
plt.plot(ages, -np.log10(m_risk), color='b', marker='s',
markeredgecolor='b', markersize=6, label='Male')
plt.xlabel('Age /years')
plt.ylabel('Risk of death (1 in $10^{-N}$)')
plt.legend(loc='upper left')
plt.title('Risk of death by age and gender')
plt.show()