Skip to content Skip to sidebar Skip to footer

Does Adding Images In Pyplot Lowers Their Resolution?

The following code from PyQt5.QtWidgets import * from PyQt5.QtCore import * from PyQt5.QtGui import * import sys from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg

Solution 1:

In the code from the question the OffsetImage is given an argument zoom=0.9. This means that each pixel of the original image takes 0.9/0.72=1.25 pixels on screen. Hence 5 pixels of the original image needs to squeezed into 4 pixels on screen. This inevitably leads to some artifacts as observed in the output of the code.

If the requirement is to show the image in the exact resolution of the original image, you need to make sure to use exactly one pixel per pixel for the OffsetImage. This would be accomplished by setting the zoom to the ppi of 72. divided by the figure dpi (100 by default).

OffsetImage(arr_img, zoom=72./self.figure.dpi)

As a result, the image shown would indeed have the same dimensions in the matplotlib plot as the original image.

enter image description here

Post a Comment for "Does Adding Images In Pyplot Lowers Their Resolution?"