|
1 |
| -#!/usr/bin/env python |
2 | 1 | '''
|
3 | 2 | Plot lines with points masked out.
|
4 | 3 |
|
5 | 4 | This would typically be used with gappy data, to
|
6 | 5 | break the line at the data gaps.
|
7 | 6 | '''
|
8 | 7 |
|
9 |
| -from pylab import * |
| 8 | +import matplotlib.pyplot as plt |
| 9 | +import numpy as np |
10 | 10 |
|
11 |
| -x = ma.arange(0, 2*pi, 0.02) |
12 |
| -y = ma.sin(x) |
13 |
| -y1 = sin(2*x) |
14 |
| -y2 = sin(3*x) |
15 |
| -ym1 = ma.masked_where(y1 > 0.5, y1) |
16 |
| -ym2 = ma.masked_where(y2 < -0.5, y2) |
| 11 | +x = np.arange(0, 2*np.pi, 0.02) |
| 12 | +y = np.sin(x) |
| 13 | +y1 = np.sin(2*x) |
| 14 | +y2 = np.sin(3*x) |
| 15 | +ym1 = np.ma.masked_where(y1 > 0.5, y1) |
| 16 | +ym2 = np.ma.masked_where(y2 < -0.5, y2) |
17 | 17 |
|
18 |
| -lines = plot(x, y, 'r', x, ym1, 'g', x, ym2, 'bo') |
19 |
| -setp(lines[0], linewidth=4) |
20 |
| -setp(lines[1], linewidth=2) |
21 |
| -setp(lines[2], markersize=10) |
| 18 | +lines = plt.plot(x, y, 'r', x, ym1, 'g', x, ym2, 'bo') |
| 19 | +plt.setp(lines[0], linewidth=4) |
| 20 | +plt.setp(lines[1], linewidth=2) |
| 21 | +plt.setp(lines[2], markersize=10) |
22 | 22 |
|
23 |
| -legend(('No mask', 'Masked if > 0.5', 'Masked if < -0.5'), |
24 |
| - loc='upper right') |
25 |
| -title('Masked line demo') |
26 |
| -show() |
| 23 | +plt.legend(('No mask', 'Masked if > 0.5', 'Masked if < -0.5'), |
| 24 | + loc='upper right') |
| 25 | +plt.title('Masked line demo') |
| 26 | +plt.show() |
0 commit comments