Frombuffer seems to default to 255

I trying to use np.frombuffer as a workaround to resize an array, but too many of the values seem to default to 255.

mat2=mat.as_array()
px = 1/plt.rcParams['figure.dpi']
fig = plt.figure(figsize=(2500*px,50*px))
plt.pcolormesh(abs(mat2))
canvas = fig.canvas
canvas.draw()
im = np.array(np.frombuffer(canvas.tostring_rgb(), dtype='uint8'))

Any ideas?

Do you expect to have any values greater than 255? If so it’s possible that setting the dtype to uint8 is what is causing your issue

I expected a “zero” in the array to become a zero (or “0, 0, 0”) on the image, but I see now it’s the opposite.

It’s not clear what the shape of mat2 is.

If it’s a 2D image, then pcolormesh with no arguments is going to autoscale the norm to fit your data, and also colour map it to viridis. If you are expecting something that is greyscale 0-255, then you need to pass that in.

No, the problem was a lot of the values turned to 255. I have solved that now, thanks. Is there a way to mark this as “solved”?