I am using BytIO to first convert the plot (matplotlib) to PNG format and then obtaining the array of the PNG image, here is the code:
from matplotlib import pyplot as plt
import numpy as np
import io
from PIL import Image
fig, ax = plt.subplots()
ax.text(0.0,0.0,"Test", fontsize=45)
ax.axis('off')
ax.imshow(np.random.random((3,3)))
with io.BytesIO() as memf:
fig.savefig(memf, format='PNG')
memf.seek(0)
img = Image.open(memf).convert('RGB')
arr = np.asarray(img)
img.show()
plt.show()
print(arr)
The image looks fine, but the array is not, it shows all values to be 255 in all 3 dimensions (RGB). What am I doing wrong?
This is the image (img):