|
1 |
| -#!/usr/bin/env python |
2 | 1 | """
|
3 | 2 | To create plots that share a common axes (visually) you can set the
|
4 | 3 | hspace between the subplots close to zero (do not use zero itself).
|
|
8 | 7 | In this example the plots share a common xaxis but you can follow the
|
9 | 8 | same logic to supply a common y axis.
|
10 | 9 | """
|
11 |
| -from pylab import * |
| 10 | +import matplotlib.pyplot as plt |
| 11 | +import numpy as np |
12 | 12 |
|
13 |
| -t = arange(0.0, 2.0, 0.01) |
| 13 | +t = np.arange(0.0, 2.0, 0.01) |
14 | 14 |
|
15 |
| -s1 = sin(2*pi*t) |
16 |
| -s2 = exp(-t) |
| 15 | +s1 = np.sin(2*np.pi*t) |
| 16 | +s2 = np.exp(-t) |
17 | 17 | s3 = s1*s2
|
18 | 18 |
|
19 | 19 | # axes rect in relative 0,1 coords left, bottom, width, height. Turn
|
20 | 20 | # off xtick labels on all but the lower plot
|
21 | 21 |
|
22 | 22 |
|
23 |
| -f = figure() |
24 |
| -subplots_adjust(hspace=0.001) |
| 23 | +f = plt.figure() |
| 24 | +plt.subplots_adjust(hspace=0.001) |
25 | 25 |
|
26 | 26 |
|
27 |
| -ax1 = subplot(311) |
| 27 | +ax1 = plt.subplot(311) |
28 | 28 | ax1.plot(t, s1)
|
29 |
| -yticks(arange(-0.9, 1.0, 0.4)) |
30 |
| -ylim(-1, 1) |
| 29 | +plt.yticks(np.arange(-0.9, 1.0, 0.4)) |
| 30 | +plt.ylim(-1, 1) |
31 | 31 |
|
32 |
| -ax2 = subplot(312, sharex=ax1) |
| 32 | +ax2 = plt.subplot(312, sharex=ax1) |
33 | 33 | ax2.plot(t, s2)
|
34 |
| -yticks(arange(0.1, 1.0, 0.2)) |
35 |
| -ylim(0, 1) |
| 34 | +plt.yticks(np.arange(0.1, 1.0, 0.2)) |
| 35 | +plt.ylim(0, 1) |
36 | 36 |
|
37 |
| -ax3 = subplot(313, sharex=ax1) |
| 37 | +ax3 = plt.subplot(313, sharex=ax1) |
38 | 38 | ax3.plot(t, s3)
|
39 |
| -yticks(arange(-0.9, 1.0, 0.4)) |
40 |
| -ylim(-1, 1) |
| 39 | +plt.yticks(np.arange(-0.9, 1.0, 0.4)) |
| 40 | +plt.ylim(-1, 1) |
41 | 41 |
|
42 | 42 | xticklabels = ax1.get_xticklabels() + ax2.get_xticklabels()
|
43 |
| -setp(xticklabels, visible=False) |
| 43 | +plt.setp(xticklabels, visible=False) |
44 | 44 |
|
45 |
| -show() |
| 45 | +plt.show() |
0 commit comments