我如何在 matplotlib imshow 中为特定像素着色?
how can i color specific pixels in matplotlib imshow?
我正在绘制一个 numpy
矩阵,其中 imshow
和蓝色比例的最近邻插值。
我如何为绘图中的特定像素着色,使它们变成红色?
pyplot.imshow(matrix, interpolation='nearest',cmap = cm.Blues)
pyplot.show()
您不能使用其中没有红色的颜色图直接将像素着色为红色。您可以选择一个红蓝颜色图并将矩阵数据规范到蓝色部分,但您也可以只在 imshow 图像上绘制:
from matplotlib import pyplot
from numpy.random import random
matrix = random((12,12))
from matplotlib import cm
pyplot.imshow(matrix, interpolation='nearest', cmap=cm.Blues)
pyplot.scatter([6,8], [10,7], color='red', s=40)
pyplot.show()
我正在绘制一个 numpy
矩阵,其中 imshow
和蓝色比例的最近邻插值。
我如何为绘图中的特定像素着色,使它们变成红色?
pyplot.imshow(matrix, interpolation='nearest',cmap = cm.Blues)
pyplot.show()
您不能使用其中没有红色的颜色图直接将像素着色为红色。您可以选择一个红蓝颜色图并将矩阵数据规范到蓝色部分,但您也可以只在 imshow 图像上绘制:
from matplotlib import pyplot
from numpy.random import random
matrix = random((12,12))
from matplotlib import cm
pyplot.imshow(matrix, interpolation='nearest', cmap=cm.Blues)
pyplot.scatter([6,8], [10,7], color='red', s=40)
pyplot.show()