wdg
wdg

Reputation: 1797

matplotlib: saved imshow pdf looks different from the plot window

The following figure was plotted using imshow in matplotlib with option interpolation='none': enter image description here However, after I saved it as a pdf file, the saved pdf file looks quite different: enter image description here The problem is: the blue patterns become very blurry.

My question is: How can I save a pdf figure that looks exactly like the plot window?

Upvotes: 1

Views: 1726

Answers (2)

charelf
charelf

Reputation: 3825

I solved this problem by specifying the dpi in the savefig for filetype pdf. Even though i read online that dpi is not supposed to make a difference in the vector based pdf format in theory, it did solve the problem for me in practice.

plt.imshow(np.random.random((10,10)))
plt.savefig("test.pdf", dpi=300)

Upvotes: 1

Christian Sarofeen
Christian Sarofeen

Reputation: 2250

PDF format is a vector image format. This means it is upto the program you open it in to interpret how it should be drawn. This can have some benefits when you want to be able to arbitrarily zoom in and out of an image while keeping high quality. However some programs can modify the image through anti-aliasing.

Your best bet for consistency is to use a pixel based image format. I would suggest try saving it as a .png.

Upvotes: 0

Related Questions