0

Consider this function 'display()'

import numpy as np
import matplotlib.pyplot as plt
from PIL import Image
from skimage import transform

def display(filename):
    img = Image.open(filename)
    img = np.array(img).astype('float32')/255
    img = transform.resize(img, (200, 200, 3))
    img = np.expand_dims(img, axis=0)
    plt.imshow(mpimg.imread(filename))
    plt.show()

Now as you know this will create a window of its own but I instead want to display the image in a PyQt5 QWidget. How do I do that?

Edit : I don't think it's a duplicate question. There is nothing about plotting images in that answer marked by eyllanesc!

Neeraj Kumar
  • 515
  • 7
  • 18
  • @eyllanesc It's not a duplicate man, come on! There is nothing about plotting images in that answer! – Neeraj Kumar Jul 23 '19 at 14:37
  • My intention with the duplicate is to guide you that you should not use pyplot but the axes with the Qt backend, if you use the following answer: https://stackoverflow.com/a/42774310/6622587 you just have to use `ax.imshow(...)` – eyllanesc Jul 23 '19 at 19:20
  • And how do I resize the canvas? It takes up all the available space. – Neeraj Kumar Jul 24 '19 at 03:31
  • canvas is a QWidget so if you want to set a fixed size then you must use `setFixedSize(w, h)`: `self.canvas.setFixedSize(100, 100)` , bye – eyllanesc Jul 24 '19 at 04:04
  • No no, that won't serve my purpose then. I think I'm better of displaying the image as a pixmap in a QLabel, thanks – Neeraj Kumar Jul 24 '19 at 10:15

0 Answers0