April 2018
Beginner to intermediate
300 pages
7h 34m
English
Next, we can adjust the alignment. We may want to adjust the margin between each subplot, or leave no margin instead of having rows and columns of discrete boxes. In this case, we can use the plt.tight_layout() function. By default, it fits all subplots into the figure area when no parameters are supplied. It takes the keyword arguments pad, w_pad, and h_pad to control the padding around subplots. Let's look at the following code example:
import matplotlib.pyplot as pltfig, axarr = plt.subplots(3,4,sharex=True,sharey=True)for i in range(3): for j in range(4): axarr[i][j].text(0.3,0.5,str(i)+','+str(j),fontsize=18)plt.tight_layout(pad=0, w_pad=-1.6, h_pad=-1)
We see from the following figure that ...
Read now
Unlock full access