Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Importing spectral breaks matplotlib's plotting abilities #44

Closed
MattFerraro opened this issue Apr 6, 2016 · 3 comments
Closed

Importing spectral breaks matplotlib's plotting abilities #44

MattFerraro opened this issue Apr 6, 2016 · 3 comments
Labels
Milestone

Comments

@MattFerraro
Copy link

This functions as expected, popping up a graphical plot:

import numpy as np
import matplotlib.pyplot as plt

A = np.array([
    [1, 2, 3],
    [4, 5, 6],
    [7, 8, 9]
])
plt.imshow(A, interpolation='nearest')
plt.show()

But this suppresses the graphical plot--it never shows up at all.

import spectral as spc      # <-- Only change is the addition of this line
import numpy as np
import matplotlib.pyplot as plt

A = np.array([
    [1, 2, 3],
    [4, 5, 6],
    [7, 8, 9]
])
plt.imshow(A, interpolation='nearest')
plt.show()

The suppressing behavior is consistent regardless of the import order.

Expected behavior is that importing spectral should have no bearing on the proper functioning of matplotlib's plots.

Working environment is on a mac, El Capitan, invoking from command line as python example.py from iterm2.

@tboggs
Copy link
Member

tboggs commented Apr 6, 2016

I was able to reproduce this behavior using the standard python interpreter (2.7.6). It did not occur for me with ipython. This appears to be due to SPy turning on matplotlib's interactive mode in spectral.spectral._init.

I agree that simply importing the spectral module shouldn't affect matplotlib's default behavior. However, I think it is reasonable to expect that once a plotting command is issued via the spectral module, matplotlib's behavior may be affected (i.e., interactive mode will be enabled). So I will move the code that changes matplotlib to interactive mode such that it will only be called when a SPy plotting command is issued.

@tboggs tboggs added the bug label Apr 6, 2016
@tboggs tboggs added this to the v0.18.0 milestone Apr 6, 2016
@MattFerraro
Copy link
Author

Thanks @tboggs! This also suggests a solution which works for me in the meanwhile:

import spectral.io.envi as envi
from matplotlib import interactive
interactive(False)
import numpy as np
import matplotlib.pyplot as plt

A = np.array([
    [1, 2, 3],
    [4, 5, 6],
    [7, 8, 9]
])
plt.imshow(A, interpolation='nearest')
plt.show()

@tboggs
Copy link
Member

tboggs commented Apr 7, 2016

Yes! I meant to suggest that as a work-around. I'm glad you thought of it too. I will have the fix in shortly. Just need to test it to make sure nothing else breaks...

@tboggs tboggs closed this as completed in cfba7b1 Apr 7, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants