]> git.friedersdorff.com Git - max/plotting_with_matplotlib.git/blob - subplot.py
feat: Add code to generate python subplot
[max/plotting_with_matplotlib.git] / subplot.py
1 import matplotlib.pyplot as plt
2 import numpy as np
3 import matplotlib.gridspec as gridspec
4
5 fig = plt.figure(tight_layout=True)
6 gs = gridspec.GridSpec(2, 3)
7
8 ax = fig.add_subplot(gs[0, :])
9 ax.plot(np.arange(0, 1e6, 1000))
10 ax.set_ylabel('YLabel0')
11 ax.set_xlabel('XLabel0')
12
13
14 for i in range(3):
15     ax = fig.add_subplot(gs[1, i])
16     ax.plot(np.arange(1., 0., -0.1) * 2000.,
17             np.arange(1., 0., -0.1))
18     ax.set_ylabel('YLabel1 %d' % i)
19     ax.set_xlabel('XLabel1 %d' % i)
20     if i == 0:
21         for tick in ax.get_xticklabels():
22             tick.set_rotation(55)
23
24 # same as fig.align_xlabels(); fig.align_ylabels()
25 fig.align_labels()
26
27 plt.show()