在图像上绘制点

时间:2020-03-05 18:56:35

标签: python matplotlib

我正在尝试绘制图像并将其指向。不幸的是,它无法按预期工作:

import numpy as np
import matplotlib.pyplot as plt
from imageio import imread

img = imread('imageio:chelsea.png')
mx, my = img.shape[:2]
P = np.array([(0,0),(mx,0),(0,my),(mx,my),(100,100)])
plt.imshow(img)
plt.plot(P[:,0], P[:,1], 'o')

enter image description here

原因是imshow会翻转轴,但是以后的绘图没有考虑到它。 我知道我可以plt.plot(P[:,1], P[:,0], 'o'),但它不能提供解决方案。

是否可以永久翻转轴?还是其他解决方案?

1 个答案:

答案 0 :(得分:0)

img中的尺寸顺序与您假设的不同。 img[i][j]是指 i j。因此,您应该写

my, mx = img.shape[:2]