1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| import matplotlib.pyplot as plt import matplotlib.transforms as mtransforms import numpy as np
xs = np.arange(7) ys = xs**2
fig = plt.figure(figsize=(5, 10)) ax = plt.subplot(2, 1, 1)
trans_offset = mtransforms.offset_copy(ax.transData, fig=fig, x=0.05, y=0.10, units='inches')
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)
ax = plt.subplot(2, 1, 2, projection='polar')
trans_offset = mtransforms.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')
plt.show()
|