import matplotlib.pyplot as plt
image = plt.imread("image.png")
fig, ax = plt.subplots(figsize=(4,3))
ax.imshow(image)
collector = {'x':0,'y':0}
def onclick(event):
collector['x'] = event.x
collector['y'] = event.y
print(collector)
cid = fig.canvas.mpl_connect('button_press_event',onclick)
plt.show()
基本上,我想要的是: 每次打印(收集器)都会返回我点击的精确值。例如{'y':267.66354838709674,'x':71.209677419354819}而不是{'y':268,'x':71} 我正在使用matplotlib 2.0.0 有什么想法吗? THX!