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

Skip to content

Commit 93f0f3b

Browse files
committed
MEP12 on transoffset.py
Changes: 1. MEP12. 2. PEP8 on syntax.
1 parent 0a5314a commit 93f0f3b

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

examples/pylab_examples/transoffset.py

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

20-
import pylab as P
20+
import matplotlib.pyplot as plt
2121
from matplotlib.transforms import offset_copy
22+
import matplotlib.transforms as tns
2223

23-
X = P.arange(7)
24-
Y = X**2
24+
xs = np.arange(7)
25+
ys = xs**2
2526

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)
2829

2930
# If we want the same offset for each text instance,
3031
# we only need to make one transform. To get the
3132
# transform argument to offset_copy, we need to make the axes
3233
# 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,
3535
x=0.05, y=0.10, units='inches')
3636

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)
4040

4141

4242
# offset_copy works for polar plots also.
43+
ax = plt.subplot(2, 1, 2, polar=True)
4344

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')
4746

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,
5251
horizontalalignment='center',
5352
verticalalignment='bottom')
5453

54+
plt.show()
5555

56-
P.show()

0 commit comments

Comments
 (0)