Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python matplotlib savefig after a few seconds bad quality image

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

enter image description here

>Solution :

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)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading