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

Skip to content

Commit bf3095e

Browse files
committed
Merge pull request #4639 from ericmjl/mep12-transoffset.py
MEP12 on transoffset.py
2 parents 8d8ec21 + e4cf4e4 commit bf3095e

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

examples/pylab_examples/transoffset.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,40 +17,40 @@
1717
offset.
1818
'''
1919

20-
import pylab as P
20+
import matplotlib.pyplot as plt
21+
import matplotlib.transforms as mtrans
22+
import numpy as np
23+
2124
from matplotlib.transforms import offset_copy
2225

23-
X = P.arange(7)
24-
Y = X**2
26+
xs = np.arange(7)
27+
ys = xs**2
2528

26-
fig = P.figure(figsize=(5, 10))
27-
ax = P.subplot(2, 1, 1)
29+
fig = plt.figure(figsize=(5, 10))
30+
ax = plt.subplot(2, 1, 1)
2831

2932
# If we want the same offset for each text instance,
3033
# we only need to make one transform. To get the
3134
# transform argument to offset_copy, we need to make the axes
3235
# first; the subplot command above is one way to do this.
36+
trans_offset = mtrans.offset_copy(ax.transData, fig=fig,
37+
x=0.05, y=0.10, units='inches')
3338

34-
transOffset = offset_copy(ax.transData, fig=fig,
35-
x=0.05, y=0.10, units='inches')
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)
39+
for x, y in zip(xs, ys):
40+
plt.plot((x,), (y,), 'ro')
41+
plt.text(x, y, '%d, %d' % (int(x), int(y)), transform=trans_offset)
4042

4143

4244
# offset_copy works for polar plots also.
45+
ax = plt.subplot(2, 1, 2, polar=True)
4346

44-
ax = P.subplot(2, 1, 2, polar=True)
45-
46-
transOffset = offset_copy(ax.transData, fig=fig, y=6, units='dots')
47-
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,
52-
horizontalalignment='center',
53-
verticalalignment='bottom')
47+
trans_offset = mtrans.offset_copy(ax.transData, fig=fig, y=6, units='dots')
5448

49+
for x, y in zip(xs, ys):
50+
plt.polar((x,), (y,), 'ro')
51+
plt.text(x, y, '%d, %d' % (int(x), int(y)),
52+
transform=trans_offset,
53+
horizontalalignment='center',
54+
verticalalignment='bottom')
5555

56-
P.show()
56+
plt.show()

0 commit comments

Comments
 (0)