#!/usr/bin/env python
# Plot Heat index graph with Matplotlib
from pylab import *
figure(figsize = (10, 9))
tt = range(20, 51)
def heat_index(t, r):
"Calculate Heat index for T (°C) and RH (%)"
c1 = -8.78469475556
c2 = 1.61139411
c3 = 2.33854883889
c4 = -.14611605
c5 = -.012308094
c6 = -.0164248277778
c7 = 2.211732e-3
c8 = 7.2546e-4
c9 = -3.582e-6
hi = c1 + c2*t + c3*r + c4*t*r + c5*t*t + c6*r*r + c7*t*t*r + c8*t*r*r + c9*t*t*r*r
return round(hi)
for r in range(100, 30, -10):
plot(tt, [heat_index(t, r) for t in tt], label = "RH = %u%%" % r,
lw = 1.5, ls = "dashed", marker = "o")
legend()
fill_between(tt, 0, 26.5, color = "#0f0", alpha = .5)
fill_between(tt, 26.5, 31.5, color = "#ff6", alpha = .5)
fill_between(tt, 31.5, 40.5, color = "#ffd700", alpha = .5)
fill_between(tt, 40.5, 53.5, color = "#ff8c00", alpha = .5)
fill_between(tt, 53.5, 200, color = "#f00", alpha = .4)
xticks(range(100))
yticks(range(150))
axis([27, 45, 27, 60])
xlabel("T [°C]")
ylabel("Heat index")
title("Heat index based on temperature and relative humidity")
grid()
savefig("heat_index_plot.svg")
show()