image rendering in PyScript

Viewed 182

after doing lots of research I managed to make Matplotlib and OpenCV work on Py-Script but Matplotlib doesn't render the result. It doesn't show the final, gray scaled image.

I have this code here :

<py-script>
import matplotlib.pyplot as plt
import numpy as np
import cv2

image = cv2.imread('1.jpg')
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
row, col = 1, 2
fig, axs = plt.subplots(row, col, figsize=(15, 10))
fig.tight_layout()
 
axs[0].imshow(cv2.cvtColor(image, cv2.COLOR_BGR2RGB))
axs[0].set_title('Original')

axs[1].imshow(cv2.cvtColor(gray_image, cv2.COLOR_BGR2RGB))
axs[1].set_title('Grayscale')

plt.show()
</py-script>

and these are my python env and configurations.

  <py-env>
    - matplotlib
    - numpy
    - opencv-python
    - paths:
      - /1.jpg
  </py-env>


  <py-config>
    - autoclose_loader: true
    - runtimes:
      -
        src: "https://cdn.jsdelivr.net/pyodide/dev/full/pyodide.js"
        name: pyodide-0.20
        lang: python
  </py-config>

in console according what I see, there is no problem. but it doesn't show any image. the code itself designed to grayscale the photo. console log of browser:

console log of browser

1 Answers

Thanks to @Tranbi. if you replace plt.show() with fig it will work

Related