# Use the traffic.read_times() function to read in "times" dict.
# Times dict has keys 0..23 for hours, values are wait-times in seconds
# for traffic at that hour over a whole year.
import traffic
times = traffic.read_times('commute-times.txt')
times
# Use traffic.div_times() to scale it down to seconds for one day.
times = traffic.div_times(times, 365)
times
# Plotting works on *lists* - make a len-24 "waits" list
# from the times dict.
waits = [times[i] for i in range(24)]
waits
# This is the canonical line to import matplotlib using the name "plt"
import matplotlib.pyplot as plt
# 1. Simplest: plot a 1-d list of values, no x-values specified
plt.plot(waits)
plt.show()
# 2. More typical, provide [ x-values ] and [ y-values ] lists
# Here we narrow the data to the hours 6..20.
# (Comprehension is not strictly needed here, but a common pattern)
plt.plot([i for i in range(6, 21)], waits[6:21])
plt.show()
# 3. Like above, but set size, add labels, can play with line color and width
plt.figure(figsize=(10, 5)) # figxize() unit is like 0.5 inch
plt.title('Commute times')
plt.xlabel('Hour of day')
plt.ylabel('Commute time in seconds')
plt.plot([i for i in range(6,21)], waits[6:21], color='green', linewidth=2)
plt.show()