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.

5
  • which backend are you using? Commented Jun 26, 2017 at 13:35
  • Excuse me I'm a newby I don't understand that question ? What backend am I using ? Commented Jun 26, 2017 at 13:35
  • 1
    matplotlib.org/faq/usage_faq.html#what-is-a-backend Commented Jun 26, 2017 at 13:47
  • What Canopy version and what Python version? Commented Jun 28, 2017 at 19:36
  • @JonathanMarch Python 2.7 and Canopy 1.7.4. Commented Jun 29, 2017 at 7:51

3 Answers 3

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')
Sign up to request clarification or add additional context in comments.

Comments

2

go to

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

set it to graphical

1 Comment

Thank you for younr answer, I am using Canopy as an IDE and I don't find IPython consol in Edit -> Preferences !
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.