Skip to content Skip to sidebar Skip to footer

How Display One White Pixel With Mathplot Imshow

I want to display one white pixel with mathplot: import numpy as np import matplotlib.pyplot as plt plt.imshow([[0.99]], cmap='gray', interpolation='nearest') plt.show() but it sh

Solution 1:

The problem is that you only give imshow one value, so the colour scale is set around that value and it gets painted as the minimum value of the scale (thus black).

Specify vmin and vmax, as shown here:

import numpy as np
import matplotlib.pyplot as plt
plt.imshow([[0.99]], cmap='gray', interpolation='nearest', vmin=0, vmax=1)
plt.show()

More importantly, you need vmax, which will be mapped to white, to be the value you give imshow, and vmin to be smaller than that:

import numpy as np
import matplotlib.pyplot as plt

max_value = np.random.random()
min_value = -max_value # for instance

plt.imshow([[max_value]], cmap='gray', interpolation='nearest',
           vmin=min_value, vmax=max_value)
plt.show()

Post a Comment for "How Display One White Pixel With Mathplot Imshow"