pythonmatplotlibfiguresubplotcanopy

plt (matplotlib) not displaying in a new window


I am trying to subplot two images myImage and reflectanceImage using matplotlib and plt , the problem is that the figure is displayed in the console not in a new window, I need to have the figure in a new seperate window in order to save it and use it outside the code.

I beleive the problem is actually concerned with the version i'm using of Linux (Ubuntu) ? Or am I missing some line of code ?

    import matplotlib.pyplot as plt
    import numpy as np
    import cv2
    
    img_directory = "/XXX/XXX/IMG_XXX.TIF"

    myImage=cv2.imread(img_directory)

    plt.figure()
    plt.subplot(221), plt.imshow(myImage),plt.title('Original Image')
    plt.subplot(222), 
    plt.imshow(np.array(reflectanceImage).reshape(1280,960).T),plt.title('Reflectance')p

Thank you for your help.


Solution

  • If you use matplotlib, you need to show the image using plt.show() unless you are not in interactive mode:

    plt.figure()
    plt.imshow(sample_image) 
    plt.show()  # display it
    

    Note: Be aware that you don't have to show the image in order to save it.

    plt.savefig('image.png')