有多种方法可以做到这一点,哪种方法更好取决于您是否需要标记大区域或分散的单个像素。
如果需要标记大区域,可以通过在图像上添加矩形来实现:
import matplotlib as mpl
import matplotlib.pyplot as plt
from numpy.random import rand
ax = plt.gca()
ax.imshow(rand(50,50))
ax.add_patch(mpl.patches.Rectangle((2,2),20,20,hatch='//////////',fill=False,snap=False))
plt.draw()
Rectangle
(doc)多种哈希选项。这只是在图像之上添加额外的艺术家,他们不会以任何方式影响数据颜色映射。数量众多/
增加散列标记的密度,这可能是实际看到小盒子的散列所必需的。
ex:
from numpy.random import rand
import matplotlib as mpl
import matplotlib.pyplot as plt
ax = plt.gca()
ax.imshow(rand(50,50),interpolation='nearest')
for i,j in np.floor(50*rand(10,2)).astype('int'):
ax.add_patch(mpl.patches.Rectangle((i-.5, j-.5), 1, 1, hatch='///////', fill=False, snap=False))
plt.draw()
If you just need to mark a few pixels here and you might be able to get away with just plotting (using plot([x],[y],marker='x')
and maybe playing with the marker size).