Skip to content

Commit

Permalink
Merge pull request #4639 from ericmjl/mep12-transoffset.py
Browse files Browse the repository at this point in the history
MEP12 on transoffset.py
  • Loading branch information
jenshnielsen committed Jul 12, 2015
2 parents 8d8ec21 + e4cf4e4 commit bf3095e
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions examples/pylab_examples/transoffset.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,40 +17,40 @@
offset.
'''

import pylab as P
import matplotlib.pyplot as plt
import matplotlib.transforms as mtrans
import numpy as np

from matplotlib.transforms import offset_copy

X = P.arange(7)
Y = X**2
xs = np.arange(7)
ys = xs**2

fig = P.figure(figsize=(5, 10))
ax = P.subplot(2, 1, 1)
fig = plt.figure(figsize=(5, 10))
ax = plt.subplot(2, 1, 1)

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

transOffset = offset_copy(ax.transData, fig=fig,
x=0.05, y=0.10, units='inches')

for x, y in zip(X, Y):
P.plot((x,), (y,), 'ro')
P.text(x, y, '%d, %d' % (int(x), int(y)), transform=transOffset)
for x, y in zip(xs, ys):
plt.plot((x,), (y,), 'ro')
plt.text(x, y, '%d, %d' % (int(x), int(y)), transform=trans_offset)


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

ax = P.subplot(2, 1, 2, polar=True)

transOffset = offset_copy(ax.transData, fig=fig, y=6, units='dots')

for x, y in zip(X, Y):
P.polar((x,), (y,), 'ro')
P.text(x, y, '%d, %d' % (int(x), int(y)),
transform=transOffset,
horizontalalignment='center',
verticalalignment='bottom')
trans_offset = mtrans.offset_copy(ax.transData, fig=fig, y=6, units='dots')

for x, y in zip(xs, ys):
plt.polar((x,), (y,), 'ro')
plt.text(x, y, '%d, %d' % (int(x), int(y)),
transform=trans_offset,
horizontalalignment='center',
verticalalignment='bottom')

P.show()
plt.show()

0 comments on commit bf3095e

Please sign in to comment.