code: def paintEvent(self, event):
          
          super(FigureCanvas, self).paintEvent(event)
          # Prepare the rect on which the image is going to be painted :
          fw = self.frameWidth()
          rect = QRect(0 + fw, 0 + fw,
                       self.size().width() - 2 * fw,
                       self.size().height() - 2 * fw)
  
          if self.fig is None or self._blink_flag:
              return
  
          # Check/update the qpixmap buffer :
          qpix2paint = None
          for qpix in self._qpix_buffer:
              if qpix.size().width() == rect.width():
                  qpix2paint = qpix
                  break
          else:
              if self.fmt in ['image/png', 'image/jpeg']:
                  qpix2paint = self._qpix_orig.scaledToWidth(
                      rect.width(), mode=Qt.SmoothTransformation)
              elif self.fmt == 'image/svg+xml':
                  qpix2paint = QPixmap(svg_to_image(self.fig, rect.size()))
              self._qpix_buffer.append(qpix2paint)
  
          if qpix2paint is not None:
              # Paint the image on the widget :
              qp = QPainter()
              qp.begin(self)
              qp.drawPixmap(rect, qpix2paint)
              qp.end()
docs: Qt method override to paint a custom image on the Widget.