Visualization in Python with matplotlib
Instead of placing each new bar above the previous one, there is one more approach to visualize such data: placing bars on the sides of other bars. We call such bar charts grouped bar charts.
The approach of building grouped bars is similar, but with some nuances. First, we need to predefine column widths. Then, we need to generate a sequence of 'positions' (preferably by using
np.arange()). Then, with every call of the
.bar() function we pass the newly created sequence as the first argument, and the values as the second. The third positional argument should be the column width. Then, for better readability, we should set the
Please note, that for building 2 columns we need to set
x - width/2as the first parameter with the first
x + width/2for the second. If we want to build three columns, we can use the following approach:
x - width,
x + width.
We may see, that there we created a
numpy array length of the same as countries, and then used approach from the note above. Also, we used the
plt.xticks function to display countries on the x-axis ticks.