Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b9b6d52

Browse files
authored
Merge pull request #8229 from dstansby/ganged-example
[MRG+1] MEP12 ganged example
2 parents 9c2412a + 8b5391c commit b9b6d52

File tree

2 files changed

+40
-45
lines changed

2 files changed

+40
-45
lines changed

examples/pylab_examples/ganged_plots.py

Lines changed: 0 additions & 45 deletions
This file was deleted.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
"""
2+
==========================
3+
Creating adjacent subplots
4+
==========================
5+
6+
To create plots that share a common axis (visually) you can set the hspace
7+
between the subplots to zero. Passing sharex=True when creating the subplots
8+
will automatically turn off all x ticks and labels except those on the bottom
9+
axis.
10+
11+
In this example the plots share a common x axis but you can follow the same
12+
logic to supply a common y axis.
13+
"""
14+
import matplotlib.pyplot as plt
15+
import numpy as np
16+
17+
t = np.arange(0.0, 2.0, 0.01)
18+
19+
s1 = np.sin(2 * np.pi * t)
20+
s2 = np.exp(-t)
21+
s3 = s1 * s2
22+
23+
fig, axs = plt.subplots(3, 1, sharex=True)
24+
# Remove horizontal space between axes
25+
fig.subplots_adjust(hspace=0)
26+
27+
# Plot each graph, and manually set the y tick values
28+
axs[0].plot(t, s1)
29+
axs[0].set_yticks(np.arange(-0.9, 1.0, 0.4))
30+
axs[0].set_ylim(-1, 1)
31+
32+
axs[1].plot(t, s2)
33+
axs[1].set_yticks(np.arange(0.1, 1.0, 0.2))
34+
axs[1].set_ylim(0, 1)
35+
36+
axs[2].plot(t, s3)
37+
axs[2].set_yticks(np.arange(-0.9, 1.0, 0.4))
38+
axs[2].set_ylim(-1, 1)
39+
40+
plt.show()

0 commit comments

Comments
 (0)