I just started with Python and installed WinPython and Spyder. The Variable Explorer is great but I cannot make it show any plots (Plot, Show Image, Histogram). Nothing happens when I select those options after choosing an array or any other type of variable.
I can get plots to show using the Console or runnin a script. However, the plt.plot() command by itself does not make a plot window to show up. I have to execute plt.show() to get the window to be created.
Can anyone help?
Thanks.
FS
(Spyder dev here) Unfortunately it seems that our plotting facilities for the Variable Explorer are not working correctly (as you discovered).
If you are using an IPython Console, they don't work at all whereas with a regular Console you need to hit Enter several times (two or three) to make the plot appear.
I opened an issue for you in our Issue tracker and we'll try to fix it in one of our next releases.
Related
I'm experiencing an issue while using VS Code to debug Python files. It seems that since last updating VS Code matplotlib figures have stopped being displayed after calls of plt.show(). There are no errors reported, and the script continues to execute as though the call had been successful, so I'm not sure what the cause is.
Initially I thought it was perhaps something to do with the backend, so I tried running in various Python environments with different matplotlib.plot backends and Python versions but no success.
My only though is that it's possible VS Code settings are overriding the backend or environment somehow and might be causing this behaviour?
I was facing the same problem inside an Anaconda's virtual environment. I created a simple script (below), when running on Ubuntu's Terminal the plot appeared, but on VSCode's Terminal the plot didn't open and the script finished.
import matplotlib.pyplot as plt
plt.plot([1,2,3], [10, 20, 30])
plt.show()
I solved by opening VSCode Settings (JSON) and changing "terminal.integrated.inheritEnv" to true. I guess you should add this option if it's not there.
Found the solution on other answer: https://stackoverflow.com/a/63368392/2014507 (credits to Jiang)
set
"terminal.integrated.inheritEnv": true,
in your user settings
#and# then don't forget to put
plt.show()
at the end of your python file. Without plt.show() your images will not be dispayed.
while accessing the file from terminal in VSCode, Save the plot, then it will be visible
plt.savefig('file_name.png')
I am using Spyder with Anaconda Launcher.
I was working on some machine learning models and when drawing graphs, I used X_grid = np.arange(min(X), max(X), 0.00000001)
Now the problem is that 0.00000001 takes a LOT of time to execute. Ideally people don't exceed 0.001.
Because of this, there is one process called "python" always showing up in the dock. If I force quit it, the kernel in Spyder dies and restarts and it instantly shows up in the dock again.
The python process icon in the dock looks like this.
I tried googling a lot, checking out answers in stackoverflow but none helped. I also tried completely removing anaconda from my mac, deleting the anaconda folder from the Users folder, then restarting the mac and then reinstalling it. Nothing seems to work! And it is really annoying to see that white icon in the dock.
So can anyone help me get rid of that white python process icon from the dock?
EDIT: I seem to have found the problem. Whenever I try to plot a graph using matplotlib, it used to appear in the console but the process icon used to not appear. To make the graph appear in a separate window, I go to Preferences > IPython Console > Graphics and select Automatic under 'Graphics Backend'. When I do this, this annoying icon appears again! Any help is appreciated.
This is mostly a question regarding work-flow in Spyder, and not a pure programming question. If anyone thinks it has no place here, then please let me know and I'll remove it.
Here we go:
I'm running Spyder on a Windows 64-bit operating system. The interaction between the Spyder IDE and IPython console depends on how you choose to run your code, and I would like to specify how this interaction works.
Among several options to run parts of the code, the difference between the following two is what puzzles me:
Option 1 - Select parts of the code and hit F9
This runs the selected code. No surprise there.
Hit F9 again, and the same selection is executed once more.
Option 2 - Run the same selection using Cells (#%%) and Ctrl+Enter
The code is run just like before. But hit Ctrl-Enter again, and nothing happens. Probably because the IPython console now is the active window.
I would like to find some way of changing this so I can use Ctrl+Enter and run the cell contents multiple times without having to make the Spyder IDE the active window by manually clicking on it. I don't know if this is possible at all. Googling and messing around in the settings under Run / configure and Tools / Preferences has so far been useless.
Thank you for any suggestions!
P.S
In case you're wondering why this is such a big deal to me, I'm rendering multiple charts and exporting them to Power Point with minor changes each time the code is run. This way, new parts of the charts (lines, textboxes, etc) are revealed when I'm working my way through a finished Power Point presentation. And for my basic data science needs, this has turned out to be a pretty much optimal work-flow. Except, of course, that I have to manually select the Spyder IDE each time I run different selections of the code.
In the latest spyder version, the keyboard shortcut to run the highlighted lines of code is F9 but it doesn't seem to work.
Go change it from TOOLS>>PREFERENCES>>KEYBOARD SHORTCUTS then double click on any shortcut you want to change and change with your shortcut. But be very careful if you used the same shortcut that is used for any other work then for that it will remove.
I changed the shortcut for 'run selection' from F9 to ctrl + Enter
in Option 2, you should use Shift+Enter instead
I recently upgraded computers and I switch from using Python to Canopy Express since all the packages I use in my coding comes included in Canopy. However, when I went to run a program I wrote that uses matplotlib to create interactive plots that I could click on data points using 'pick_event' in Canopy, I'm getting a few issues with the program that I didn't have in Python. When I run the program, Canopy displays the graph and then immediately moves to the next line of code. This creates a problem for me since I want the graph to be interactive and it doesn't give me a chance to choose my data points I want. I have found ways to leave the graph up (adding in a raw input after displaying the plot or not closing the plot in the program) but Canopy crashes when I try to move or click on the plot. Is there any way I can fix this issue so I can use 'pick_event' command?
Thanks for the help
It seems likely that your code is not written to optionally run in IPython's %pylab mode (or, equivalently in this context, %matplotlib mode), which starts a GUI event loop for you and in many cases makes interactions between prompt and GUI easier. You might consider adapting your code to be able to do this, but meanwhile you can test this hypothesis by disabling pylab mode in the Canopy Preference menu (Python tab).
This article may be relevant:
Using Wx/WxPython in Canopy's IPython panel
I actually know a problem in Spyder. When I Work with matplotlib.pyplot, it automatically shows the figure without any kind of plt.show(). So when I make many different figures, it always shows them all on the same.
I've recently made a program, which is saving one figure by iteration in an for loop, it also opens a figure and at the end, the loop crashes before ending because of too many figures showed.
I would like to know if someone also knows such problems, because I've encountered the in many computers running spyder
You likely are running in iPython with Spyder. iPython automatically runs plt.show(). Press f6 (default), and see if "execute in current python or iPython console" is selected. If so, check the console, the 'tab' should show a blue icon with "iP" and have 'kernal' (or similar) following it.
Simple fix: switch to "execute in dedicated python console" or open a new python console (tab header "python 1")
Source: had same problem.