Image saved in google Colabs Notebook is not identical to the image saved in local machine

Viewed 309

I have created a figure using matplotlib and saved it using savefig function. following is the code i used,

import matplotlib.pyplot as plt

x = [0, 2, 4, 6]
y = [1, 3, 4, 8]

plt.plot(x,y)
plt.xticks([]), plt.yticks([])
plt.box(False)
plt.savefig('plot.png')
plt.show()

When i run the following code in google colabs it generates an image with the size of 432 x 288 When i run the same code in my local machine it will generates an image with the size of 640 x 480

so i tried to resize the image which i generated in local machine by adding the following changes

plt.figure(figsize=(4.32, 2.88))

Using the below code to verify that both images are exactly the same, but they are not identical.

import PIL.Image, PIL.ImageChops
im1 = PIL.Image.open(colab_image.png') 
im2 = PIL.Image.open(local_image.png')
if list(im1.getdata()) == list(im2.getdata()): 
    print("Identical");
else:
    print("Different");

Both colab and my local machine environment has -> python 3.7.0 64bit, matplotlib == 3.2.2

Please please help me to figure this issue.Because, I have no idea why this is happening. Your hep will be highly appreciated.

Here is the link for the colab notebook

Thanks and best regards.

1 Answers

I think there might be an Operating System compatibility issue. Please check the code with windows and Linux/Mac environments separately.

Related