]> git.friedersdorff.com Git - max/plotting_with_matplotlib.git/commitdiff
feat: Add code to generate python subplot
authorMaximilian Friedersdorff <max@friedersdorff.com>
Mon, 28 Jan 2019 19:36:36 +0000 (19:36 +0000)
committerMaximilian Friedersdorff <max@friedersdorff.com>
Mon, 28 Jan 2019 19:36:36 +0000 (19:36 +0000)
subplot.py [new file with mode: 0644]

diff --git a/subplot.py b/subplot.py
new file mode 100644 (file)
index 0000000..d817ec5
--- /dev/null
@@ -0,0 +1,27 @@
+import matplotlib.pyplot as plt
+import numpy as np
+import matplotlib.gridspec as gridspec
+
+fig = plt.figure(tight_layout=True)
+gs = gridspec.GridSpec(2, 3)
+
+ax = fig.add_subplot(gs[0, :])
+ax.plot(np.arange(0, 1e6, 1000))
+ax.set_ylabel('YLabel0')
+ax.set_xlabel('XLabel0')
+
+
+for i in range(3):
+    ax = fig.add_subplot(gs[1, i])
+    ax.plot(np.arange(1., 0., -0.1) * 2000.,
+            np.arange(1., 0., -0.1))
+    ax.set_ylabel('YLabel1 %d' % i)
+    ax.set_xlabel('XLabel1 %d' % i)
+    if i == 0:
+        for tick in ax.get_xticklabels():
+            tick.set_rotation(55)
+
+# same as fig.align_xlabels(); fig.align_ylabels()
+fig.align_labels()
+
+plt.show()