-
Book Overview & Buying
-
Table Of Contents
Learning Pandas
By :
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 ax1, is located in the first row (loc=(0,0)), and the second, referred to as ax2, is in the second row (loc=(1,0)):
In [41]: # create two sub plots on the new plot using a 2x1 grid # ax1 is the upper row ax1 = plt.subplot2grid(shape=(2,1),...
Change the font size
Change margin width
Change background colour