这样做非常简单,但要了解正在发生的事情,您需要阅读有关matplotlib变换的内容.
transformations tutorial是一个很好的起点.
无论如何,这是一个例子:
import numpy as np
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
points, = ax.plot(range(10), 'ro')
ax.axis([-1, 10, -1, 10])
# Get the x and y data and transform it into pixel coordinates
x, y = points.get_data()
xy_pixels = ax.transData.transform(np.vstack([x,y]).T)
xpix, ypix = xy_pixels.T
# In matplotlib, 0,0 is the lower left corner, whereas it's usually the upper
# right for most image software, so we'll flip the y-coords...
width, height = fig.canvas.get_width_height()
ypix = height - ypix
print 'Coordinates of the points in pixel coordinates...'
for xp, yp in zip(xpix, ypix):
print '{x:0.2f}\t{y:0.2f}'.format(x=xp,