Skip to content
scipython.com

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
< 1227177
1 - 453764386
5 - 14104178333
15 - 2441321908
25 - 34 24881215
35 - 441106663
45 - 54421279
55 - 64178112
65 - 746542
75 - 842115
> 8476
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()

Annual risk of death plotted by age and gender