October 2018
Beginner to intermediate
676 pages
18h 30m
English
In the preceding example, we used width_ratios and height_ratios arguments to define the required grid using GridSpec(). The same arguments can be passed on to plt.subplots() to plot a similar grid that we created in the preceding example. Here is the code:
widths = [2, 3, 1.5]heights = [1, 3, 2]t = np.arange(0.0, 1.0, 0.01)s = np.sin(2*np.pi*t)### Passing keyword specs to pltgs_kw = dict(width_ratios=widths, height_ratios=heights)fig, axes = plt.subplots(ncols=3, nrows=3, figsize=(10,8), gridspec_kw=gs_kw)for r, row in enumerate(axes): for c, ax in enumerate(row): ax.plot(t, s) label = 'Width: {}\nHeight: {}'.format(widths[c], heights[r]) ax.annotate(label, (0.1, 0.5), xycoords='axes fraction', va='center')fig.tight_layout() ...Read now
Unlock full access