2

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.

Mourad Over Flow
  • 191
  • 1
  • 5
  • 16

3 Answers3

6

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')
mrk
  • 8,059
  • 3
  • 56
  • 78
2

go to

Tools -> Preferences -> IPython consol -> Completion Type 

set it to graphical

mrk
  • 8,059
  • 3
  • 56
  • 78
0

By default, Canopy runs its IPython kernel in pylab qt mode; in this mode, windows do pop up in a new window. Because they are not doing this for you, it seems likely that for some reason in the past you changed the setting to pylab inline mode. (Perhaps because you wanted to run a TK program, as here?)

Please reset it to qt (Edit=>Preferences=>Python=>backend=qt). Does it now act as expected?

BTW, the current version of Canopy is 2.1.3.

Jonathan March
  • 5,800
  • 2
  • 14
  • 16