您可以使用网格。
例如见https://docs.scipy.org/doc/numpy/reference/generated/numpy.meshgrid.html
“meshgrid 对于评估网格上的函数非常有用。”
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> x = np.arange(-5, 5, 0.1)
>>> y = np.arange(-5, 5, 0.1)
>>> xx, yy = np.meshgrid(x, y, sparse=True)
>>> z = np.sin(xx**2 + yy**2) / (xx**2 + yy**2)
>>> h = plt.contourf(x,y,z)
>>> plt.show()
或者不使用网格网格,您也可以使用两个向量来索引图像:
假设您的画布保存在变量im 中,您可以将原点位于底部中间的两个笛卡尔轴,然后使用它们来索引图像的像素:
x = np.arange(minx, maxx, 1)
y = np.arange(0, maxy, 1)
其中minx 和maxx 应该是-(im.shape[1] / 2) 和(im.shape[1] / 2)(假设您的画布有偶数列。
最后得到一个坐标,例如coord=(your_x, your_y)来自im:
im[np.where(y==coord[1])[0], np.where(x==coord[0])[0]]