
上QQ阅读APP看书,第一时间看更新
How it works...
Here is the explanation of how it works:
- fig, ax = plt.subplots(1, 3, figsize=(10,4)) defines the figure layout.
- fig.subplots_adjust(wspace=0.5) adjusts the space in between the subplots.
- ax[0].hist(np.random.randn(1000)) plots the histogram on axes 0, followed by labels for the X and Y axes, then title for the plot.
- ax[0].set_title() includes font style and size arguments apart from the title text, but it does not have the color argument; hence, we use plt.setp(atitle,color='blue') to set the color for the title.
- plt.rcParams['axes.labelsize'] = 10 and plt.rcParams['axes.labelweight'] = 'bold' set the font size and weight for x and y axes labels for all the plots. Here, we have labels only for the first plot, hence, they are shown in bold with a fontsize of 10.
- p1 and p2 are the bar plots on axis one for men and women. ax[1].set_xticks(ind + width / 2) sets the ticks followed by ax[1].set_xticklabels(('C1', 'C2', 'C3', 'C4', 'C5')), setting ticklabels on the x axis. For the y axis, we are using default ticks and ticklabels as applicable for a logarithmic scale. Typically, we override ticklables for categorical variables to give meaningful names.
- Finally, plt.suptitle() and plt.setp() define the title for the overall figure for a given font name, size, and color.
- plt.tight_layout(pad=3) adjusts the space between plots, and pad=3 adjusts the space between the figure title and the individual plot titles so that there is no overlap between them.
We get the output as follows: