October 2018
Beginner to intermediate
676 pages
18h 30m
English
The following code draws a bar plot:
month_num = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]units_sold = [500, 600, 750, 900, 1100, 1050, 1000, 950, 800, 700, 550, 450]
fig, ax = plt.subplots()
plt.xticks(month_num, calendar.month_name[1:13], rotation=20)
plot = ax.bar(month_num, units_sold)
for rect in plot: height = rect.get_height() ax.text(rect.get_x() + rect.get_width()/2., 1.002*height,'%d' % int(height), ha='center', va='bottom')
plt.show()
Read now
Unlock full access