I\'ve recently started using sublimetext 2, however I noticed today that the plt.show()
function doesn\'t seem to work when run within sublimetext.
If
I tried out theta's answer as suggested above. It works fine. In case the console opens and closes instantly like running python files directly from file explorer, just add the following line at the end:
matplotlib.pyplot.show('hold')
Its my first time answering here. Sorry if I didn't adhere to the answer format.
More appropriate way is to just add one line in default Python build system file:
"shell": true
Or make additional Python build system with:
{
"cmd": ["python", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python",
"shell": true
}
I had a similar issue under Ubuntu. I was trying to plot a pandas
DataFrame
like this:
df = pandas.DataFrame([*range(5)])
df.plot()
But the plot did not show. Turns out you need to do plt.show()
, as discussed here.
Note in sublime text 3 (with anaconda package installed)
You need to add a custom build system as theta said, by:
first add a folder named python in \path\to\Sublime Text Build XXXX\Data\Packages
then put a file named python.sublime-build
into that folder.
{
"cmd": ["python", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python",
"shell": true
}
and remember to add plt.show()
like Roald said.
plt.imshow(image)
plt.show()
Demo:
My guess would be that Sublime Text 2 launches your code in its own environment, and only traps and displays the console output. The same problem exists when using GUI's, such as wxPython.
Another work around is to open the command prompt and launch it manually (python file.py).
EDIT: Here it states that "Under Windows, GUIs are supressed."
EDIT 2: Here it lists a way to fix it, right at the bottom of the page.