Multiple plots in a single chart
It is often useful to contrast data by displaying multiple plots next to each other. This is actually quite easy to when using matplotlib.
To draw multiple subplots on a grid, we can make multiple calls to plt.subplot2grid()
, each time passing the size of the grid the subplot is to be located on (shape=(height, width)
) and the location on the grid of the upper-left section of the subplot (loc=(row, column)
). Each call to plt.subplot2grid()
returns a different AxesSubplot
object that can be used to reference the specific subplot and direct the rendering into.
The following demonstrates this, by creating a plot with two subplots based on a two row by one column grid (shape=(2,1)
). The first subplot, referred to by ...
Get Learning pandas now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.