Skip to content

Instantly share code, notes, and snippets.

@nicoguaro
Last active July 29, 2019 23:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicoguaro/09ce0fe59a3e181d256c75e9bdcce096 to your computer and use it in GitHub Desktop.
Save nicoguaro/09ce0fe59a3e181d256c75e9bdcce096 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Evaluation of ranges for Avverage annual global temperature
in Fahrenheit.
It was motivated by
https://eagereyes.org/blog/2019/what-is-a-misleading-chart
@author: Nicolas Guarin-Zapata
@date: July 25, 2019
"""
import numpy as np
import matplotlib.pyplot as plt
plt.style.use("seaborn")
#% Data
year = np.arange(1880, 2010, 10)
data = np.array([
[13.73, 56.71],
[13.75, 56.74],
[13.74, 56.73],
[13.72, 56.7 ],
[13.83, 56.89],
[13.96, 57.12],
[14.04, 57.26],
[13.98, 57.16],
[13.99, 57.18],
[14. , 57.2 ],
[14.18, 57.52],
[14.31, 57.76],
[14.51, 58.12]])
#%%
plt.close("all")
plt.figure()
plt.suptitle("Average Annual Global Temperature in Fahrenheit\n1880-2000")
# Option 1: Shown in the article
plt.subplot(4, 1, 1)
plt.plot(year, data[:, 1])
plt.ylim(0, 100)
xticks, _ = plt.xticks()
plt.xticks(year, [])
# Option 2: Water as reference
plt.subplot(4, 1, 2)
plt.plot(year, data[:, 1])
plt.ylim(32, 212)
plt.xticks(year, [])
# Option 3: Matplotlib Default
plt.subplot(4, 1, 3)
plt.plot(year, data[:, 1])
plt.xticks(year, [])
# Option 4: Manually tweaked
temp_range = 4 # According to fever changes (?)
average = data[:, 1].mean()
plt.subplot(4, 1, 4)
plt.plot(year, data[:, 1])
plt.ylim(average - temp_range, average + temp_range)
plt.xticks(year, year)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment