So this is my analysis, feel free to ask me if somethings not clear:
hour = range(24)
#hour is declared as a Python range of consecutive numbers, from 0 to 23 (remember 24 digits starting from 0 so the highest is 23)
viewers_hour = [30, 17, 34, 29, 19, 14, 3, 2, 4, 9, 5, 48, 62, 58, 40, 51, 69, 55, 76, 81, 102, 120, 71, 63]
#viewers_hour is a list of made-up numbers, they represent an example of the total hours spent by Code Academy users on the platform on a full day, see how the list is made up of 24 numbers?
plt.title(“Codecademy Learners Time Series”)
#declaring a title for the graph
plt.xlabel(“Hour”)
#naming the x axis
plt.ylabel(“Viewers”)
#naming the y axis
plt.plot(hour, viewers_hour)
#creating the graph, the values of hour are the X and the values of viewers_hour are the Y
plt.legend([‘2015-01-01’])
#the graphs legend
ax = plt.subplot()
#now this was curious, seems that a subplot (which allows us to draw another graph on top of our current one) is necessary for:
ax.set_facecolor(‘seashell’)
#set the graph’s yellowish background color
ax.set_xticks(hour)
#make it so that all 24 values in hour show up in the X axis
ax.set_yticks([0, 20, 40, 60, 80, 100, 120])
#define the values of the ticks on Y
#interestingly I tried doing this on the original graph and it didn’t work! like this:
#plt.set_xticks(hour)
#plt.set_yticks([0, 20, 40, 60, 80, 100, 120])
#plt.set_facecolor(‘seashell’)
#why did this not work? I have no idea!
#That’s it for the use of the ax subplot!
y_upper = [i + (i*0.15) for i in viewers_hour]
#this creates a new viewers_hour list but the values are slightly larger
y_lower = [i - (i*0.15) for i in viewers_hour]
#this creates a new viewers_hour list but the values are slightly smaller
plt.fill_between(hour, y_lower, y_upper, alpha=0.2)
#this adds color to the gap between the slightly larger and smaller values
plt.show()
#this shows the graph
#funnily enough ax.show() works identically