You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
explore_math/ch2_graphing/temp_comparision_v2.py

33 lines
786 B
Python

import numpy as np
import matplotlib.pyplot as plt
nyc_temp_2000 = np.array([
31.3, 37.3, 47.2, 51.0, 63.5, 71.3,
72.3, 72.7, 66.0, 57.0, 45.3, 31.1
])
nyc_temp_2006 = np.array([
40.9, 35.7, 43.1, 55.7, 63.1, 71.0,
77.9, 75.8, 66.6, 56.2, 51.9, 43.6
])
nyc_temp_2012 = np.array([
37.3, 40.9, 50.9, 54.8, 65.1, 71.0,
78.8, 76.7, 68.8, 58.0, 43.9, 41.5
])
months = np.arange(1, 13)
fig, ax = plt.subplots()
ax.plot(months, nyc_temp_2000, marker="o", label="2000")
ax.plot(months, nyc_temp_2006, marker="o", label="2006")
ax.plot(months, nyc_temp_2012, marker="o", label="2012")
ax.set_title("Average monthly temperature in NYC")
ax.set_xlabel("Month")
ax.set_ylabel("Temperature")
ax.set_ylim(bottom=0) # equivalent to axis(ymin=0)
ax.legend()
plt.show()