|
17 | 17 | offset.
|
18 | 18 | '''
|
19 | 19 |
|
20 |
| -import pylab as P |
| 20 | +import matplotlib.pyplot as plt |
21 | 21 | from matplotlib.transforms import offset_copy
|
| 22 | +import matplotlib.transforms as tns |
22 | 23 |
|
23 |
| -X = P.arange(7) |
24 |
| -Y = X**2 |
| 24 | +xs = np.arange(7) |
| 25 | +ys = xs**2 |
25 | 26 |
|
26 |
| -fig = P.figure(figsize=(5, 10)) |
27 |
| -ax = P.subplot(2, 1, 1) |
| 27 | +fig = plt.figure(figsize=(5, 10)) |
| 28 | +ax = plt.subplot(2, 1, 1) |
28 | 29 |
|
29 | 30 | # If we want the same offset for each text instance,
|
30 | 31 | # we only need to make one transform. To get the
|
31 | 32 | # transform argument to offset_copy, we need to make the axes
|
32 | 33 | # first; the subplot command above is one way to do this.
|
33 |
| - |
34 |
| -transOffset = offset_copy(ax.transData, fig=fig, |
| 34 | +trans_offset = tns.offset_copy(ax.transData, fig=fig, |
35 | 35 | x=0.05, y=0.10, units='inches')
|
36 | 36 |
|
37 |
| -for x, y in zip(X, Y): |
38 |
| - P.plot((x,), (y,), 'ro') |
39 |
| - P.text(x, y, '%d, %d' % (int(x), int(y)), transform=transOffset) |
| 37 | +for x, y in zip(xs, ys): |
| 38 | + plt.plot((x,), (y,), 'ro') |
| 39 | + plt.text(x, y, '%d, %d' % (int(x), int(y)), transform=trans_offset) |
40 | 40 |
|
41 | 41 |
|
42 | 42 | # offset_copy works for polar plots also.
|
| 43 | +ax = plt.subplot(2, 1, 2, polar=True) |
43 | 44 |
|
44 |
| -ax = P.subplot(2, 1, 2, polar=True) |
45 |
| - |
46 |
| -transOffset = offset_copy(ax.transData, fig=fig, y=6, units='dots') |
| 45 | +trans_offset = tns.offset_copy(ax.transData, fig=fig, y=6, units='dots') |
47 | 46 |
|
48 |
| -for x, y in zip(X, Y): |
49 |
| - P.polar((x,), (y,), 'ro') |
50 |
| - P.text(x, y, '%d, %d' % (int(x), int(y)), |
51 |
| - transform=transOffset, |
| 47 | +for x, y in zip(xs, ys): |
| 48 | + plt.polar((x,), (y,), 'ro') |
| 49 | + plt.text(x, y, '%d, %d' % (int(x), int(y)), |
| 50 | + transform=trans_offset, |
52 | 51 | horizontalalignment='center',
|
53 | 52 | verticalalignment='bottom')
|
54 | 53 |
|
| 54 | +plt.show() |
55 | 55 |
|
56 |
| -P.show() |
0 commit comments