Hello everybody.
I’m a French physic teacher and also in informatic with python. (i request your apologyze for my english… you know…)
I’m trying to build an homemade image, by this code :
import numpy as np
import matplotlib.pyplot as plt
def image_unie(largeur,hauteur,couleur):
matrice=[ ]
for ligne in range(0,hauteur):
c=[ ]
for colonne in range(0,largeur):
pixel=couleur
c.append(pixel)
matrice.append(c)
matrice2=np.array(matrice)
return matrice2
test_blanc=image_unie(500,500,[0,255,0])
plt.imshow(test_blanc)
plt.show()
It shows an all black rectangle…
But if i tried it on another PC, it works (green rectangle)… Is there an option on imshow to force rgb ?
Thx for helping !
[edited by @tacaswell to fix formatting]
First, there are easier ways to get the image:
def image_unie(largeur,hauteur,couleur):
return np.ones((hauter, lauger, 3), dtype=int) * couleur
Do you mean you get an all black image or do you mean the whole GUI window is black (e.g. no tick labels etc)?
If the first, do you get the warning:
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
on the computer that does not work? If so, ensuring the values are integers may solve the problem.
Hello,
Thx a lot.
I mean i have an all black image.
I understand that in some computer, color must be between 0 and 1, and not 0 and 255 ! It should depends on the version of matplotlib. But i can’t upgrade it.
I read it can be an option for “imshow” to force the scale of color between 0 and 255 but i’m not able to find it !
(is my message understable ? from 0 to 10 !)
Vincent
What are the versions of Matplotlib that you are using?