I have troubles with saving numpy two-dimensional array as image (in grayscale). I read this question Save plot to image file instead of displaying it using Matplotlib, but still don't understand what's wrong with the following code.
plt.imsave("image.eps", np.flipud(arr), cmap = "gray_r", format = "eps", dpi = 1000)
After execution the image.eps is blank and I don't understand why. I also tried to deal with it as an AxesImage object (see below) but without success.
img = plt.imshow(np.flipud(arr))
plt.savefig("image.eps", format = "eps", dpi = 1000)
Please, explain me what's wrong with this code.
Actually, I am new to Python (and to matplotlib as well), so I am not familiar with many ideas of Python.
Update: I tried the following code but the image.eps is still blank.
import matplotlib.pyplot as plt
import numpy as np
arr = np.array([[1, 0.5],[0.5, 0]])
plt.imsave("image.eps", np.flipud(arr), cmap = "gray_r", format = "eps", dpi = 1000)
On the other hand if I call
img = plt.imshow(arr)
then I can see in the console (Spyder) the correct picture (one black, one white and two gray squares).
Maybe there is some way to save the picture using the img-variable?