Last active
July 9, 2025 00:12
-
-
Save Nikolaj-K/ac10fa058e806e84f136ef717a29b141 to your computer and use it in GitHub Desktop.
Plot people's overlapping lifespan with bars
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
IMAGE_DIRPATH = r"your/path/to/lifespans.png" | |
PEOPLE = [ | |
("Voltaire", 1694, 1778, "Philosopher"), | |
("Hume", 1711, 1776, "Philosopher"), | |
("Rousseau", 1712, 1778, "Philosopher"), | |
("Kant", 1724, 1804, "Philosopher"), | |
("Fichte", 1762, 1814, "Philosopher"), | |
("Hegel", 1770, 1831, "Philosopher"), | |
("Schelling", 1775, 1854, "Philosopher"), | |
("Schopenhauer", 1788, 1860, "Philosopher"), | |
("Stirner", 1806, 1856, "Philosopher"), | |
("Kierkegaard", 1813, 1855, "Philosopher"), | |
("Marx", 1818, 1883, "Philosopher"), | |
("Nietzsche", 1844, 1900, "Philosopher"), | |
("Peirce", 1839, 1914, "Philosopher"), | |
("Euler", 1707, 1783, "Mathematician"), | |
("Lagrange", 1736, 1813, "Mathematician"), | |
("Laplace", 1749, 1827, "Mathematician"), | |
("Gauss", 1777, 1855, "Mathematician"), | |
("Cauchy", 1789, 1857, "Mathematician"), | |
("Jacobi", 1804, 1851, "Mathematician"), | |
("Abel", 1802, 1829, "Mathematician"), | |
("Galois", 1811, 1832, "Mathematician"), | |
("Dedekind", 1831, 1916, "Mathematician"), | |
("Riemann", 1826, 1866, "Mathematician"), | |
("Hilbert", 1862, 1943, "Mathematician"), | |
("Klein", 1849, 1925, "Mathematician"), | |
("Noether", 1882, 1935, "Mathematician"), | |
("Cantor", 1845, 1918, "Mathematician"), | |
("Poincaré", 1854, 1912, "Mathematician"), | |
("Fourier", 1768, 1830, "Mathematician"), | |
("Coulomb", 1736, 1806, "Physicist"), | |
("Ampère", 1775, 1836, "Physicist"), | |
("Faraday", 1791, 1867, "Physicist"), | |
("Maxwell", 1831, 1879, "Physicist"), | |
("Kelvin", 1824, 1907, "Physicist"), | |
("Boltzmann", 1844, 1906, "Physicist"), | |
("Planck", 1858, 1947, "Physicist"), | |
("Einstein", 1879, 1955, "Physicist"), | |
("Curie", 1867, 1934, "Physicist"), | |
("Heisenberg", 1901, 1976, "Physicist"), | |
("Fermi", 1901, 1954, "Physicist"), | |
("Maria Theresa", 1717, 1780, "Politician"), | |
("Napoleon", 1769, 1821, "Politician"), | |
("Metternich", 1773, 1859, "Politician"), | |
("Bismarck", 1815, 1898, "Politician"), | |
("Lincoln", 1809, 1865, "Politician"), | |
("Roosevelt", 1858, 1919, "Politician"), | |
("Churchill", 1874, 1965, "Politician"), | |
#("Descartes", 1596, 1650, "Philosopher"), | |
#("Spinoza", 1632, 1677, "Philosopher"), | |
#("Locke", 1632, 1704, "Philosopher"), | |
#("Leibniz", 1646, 1716, "Philosopher"), #"Mathematician" | |
#("Berkeley", 1685, 1753, "Philosopher"), | |
#("William James", 1842, 1910, "Philosopher"), | |
#("Bergson", 1859, 1941, "Philosopher"), | |
#("Pascal", 1623, 1662, "Mathematician"), | |
#("Galileo", 1564, 1642, "Physicist"), | |
#("Newton", 1643, 1727, "Physicist"), # "Mathematician" | |
#("Franz Joseph I", 1830, 1916, "Politician"), | |
#("Queen Victoria", 1819, 1901, "Politician"), | |
#("Rutherford", 1871, 1937, "Physicist"), | |
#("Benjamin Disraeli", 1804, 1881, "Politician"), | |
#("Woodrow Wilson", 1856, 1924, "Politician"), | |
#("Hawking", 1942, 2018, "Physicist"), | |
#("Louis XIV", 1638, 1715, "Politician"), | |
#("Peter the Great", 1672, 1725, "Politician"), | |
#("Frederick the Great", 1712, 1786, "Politician"), | |
#("Catherine the Great", 1729, 1796, "Politician"), | |
] | |
COLORS = { | |
"Philosopher": "#1f77b4", | |
"Mathematician": "#ff7f0e", | |
"Physicist": "#2ca02c", | |
"Politician": "#d62728", | |
} | |
def make_plot(people_sorted: list): | |
fig, ax = plt.subplots(figsize=(8, 14)) # updated size | |
for year in range(1700, 2000, 50): | |
ax.axvline(x=year, color='gray', linestyle='--', linewidth=0.8, alpha=0.5) | |
ax.text(year, -1.5, str(year), ha='center', va='bottom', fontsize=8, color='gray') | |
for idx, (name, birth, death, cat) in enumerate(people_sorted): | |
ax.barh(idx, death - birth, left=birth, color=COLORS[cat], edgecolor='black') | |
ax.text(death + 1, idx, name, va='center', fontsize=10) | |
ax.set_xlabel("Year") | |
ylim_lower: int = people_sorted[0][1] - 3 | |
ax.set_xlim(ylim_lower, 2025) | |
ax.set_yticks([]) | |
ax.invert_yaxis() | |
plt.subplots_adjust(top=0.93) | |
plt.tight_layout() | |
plt.show() | |
fig.savefig(IMAGE_DIRPATH, dpi=300, bbox_inches='tight') | |
if __name__ == '__main__': | |
make_plot(sorted(PEOPLE, key=lambda x: x[1])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment