0

I have a numpy array, and I use following codes to draw a simple picture.

import numpy as np
from matplotlib import pyplot as plt
plt.show(image, cmap='gray')

I also have a list containing the several positions of the image, and I'd like to change the colors of these positions on the same picture. For example, I have another list like this:

pos = [(0,1),(3,6)...]

I'd like to change the pixel's color according to this. For other pixels they remain the same. How can I do that?

PennYan
  • 13
  • 4
  • I hope {this answer](https://stackoverflow.com/questions/26692946/changing-colours-of-pixels-of-plt-imshow-image) will help you. This example is a way to normalize the colormap used and graph it, specifying the RGBA of the color at a particular location in the range from 0 to 1 – r-beginners Mar 25 '22 at 04:42

1 Answers1

0

If you don't mind copying or modifying the image you can acess the pixel value in the array :

import numpy as np

image = np.eye(10)

pos = [(0,1),(3,6)]
values_to_set  = [125,255]
for p, val in zip(pos, values_to_set):
    image[p] = val
endive1783
  • 827
  • 1
  • 8
  • 18