最简单的解决方案包括首先计算输入数据的 RGBA 颜色,对其进行操作以设置与您的特殊颜色(绿色)不同的值,然后使用简单imshow()
的修改后的 RGBA 数组进行绘图。这是如何做到的:
>>> rgba_values = cm.gray(y) # All RGBA values for your input value, with levels of gray
>>> rgba_values[x != y] = [0, 1, 0, 1] # Set the points where x and y differ to green (RBG = 0, 1, 0)
>>> imshow(rgba_values, interpolation='nearest')
x
数组之间不同的数据点y
现在为绿色:
如果您想在之前显示的图像上覆盖绿色点,您可以执行类似的操作并将 alpha 通道设置为 0,您不想修改原始图像:
>>> y_gray = cm.gray(y) # RGBA image with gray levels
>>> imshow(y_gray, interpolation='nearest') # Image of one of the arrays
>>> diff_points = numpy.empty_like(y_gray) # Preparation of an overlay with marked points only
>>> diff_points[x == y, 3] = 0 # Common points not overwritten: alpha layer set to 0
>>> diff_points[x != y] = [0, 1, 0, 1] # Green for points that differ
>>> imshow(diff_points, interpolation='nearest')