Python matplotlib savefig after a few seconds bad quality image

Question:

when I save an image with plt.savefig(dpi=300)
a few seconds after opening it my image text becomes bad quality,
what is driving this issue?

I tried different dpi’s, like 500, 1000 but no help. For 2/3 seconds the image is of good quality then defaults to as the image below shows:

A small part of the chart on the x-axis, and the image quality.

enter image description here

Asked By: darkuss

||

Answers:

It sounds like the issue you are encountering may be related to the way that the image is being displayed on your computer. When you use the plt.savefig() method to save an image with a high DPI (dots per inch), the image will have more pixels per inch, which can result in a higher quality image. However, depending on how the image is being displayed on your computer, it may be downsampled or resized to fit the screen, which can result in a lower quality image.

One way to avoid this issue is to save the image in a vector format, such as PDF or SVG, instead of a raster format like PNG or JPG. Vector images are not subject to the same downsampling and resizing issues as raster images, and they can be scaled to any size without losing quality.

To save your image as a PDF or SVG file, you can use the savefig() method and specify the file format using the format parameter. For example, to save your image as a PDF file, you could use the following code:

# Save the image as a PDF file with a high DPI

plt.savefig('my_image.pdf', format='pdf', dpi=300)
Answered By: Cristian Zúñiga
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.