August 2017
Beginner to intermediate
334 pages
8h 22m
English
Sometimes we would prefer more exact values than guess between ticks on axes. To automatically retrieve and label data values on a bar graph, we can define our own function to put text above each bar. Essentially, the pyplot.bar() function creates a list of rectangles with assigned dimensions. What we do is collect these dimensions to determine the location of the text to be added.
We are recycling the previous non-resident arrivals figure. We can add the following code block of the value-labeling function and call it after defining ax1.bar() to add value labels above each bar:
# Prepare the bar value labelling functiondef autolabel(rects): """ Attach a text label above each bar displaying its height Adapted ...
Read now
Unlock full access