I'm using Spyder3.1.2 IDE with Python 3.5 in Windows 10 and would like to know how to choose whether to show my plots in the iPython console or in a separate window. I found this other question but I get an error when I type %matplotlib qt (No module named PyQt4). I have also changed the preferences to show graphics "automatically" instead of "inline", but I'm still getting them inline.
What I want to end up with is a for loop where on every iteration I add a new point to my graph, which is visible immediately and is shown in a separate window to the console.
Many thanks for your time
You can run your script in a new python console every time you run it.
For that press F6 or go to Run/Configure... and select "Execute in a new dedicated Python console.
Since this python console will not be an IPython console, there is no need to perform any other settings.
The plot should show up in a window upon plt.show().
Related
when using VSCode, I can run python files in cells/parts as if it was Jupyter notebook, without actually having a notebook.
https://code.visualstudio.com/docs/python/jupyter-support-py
It means, you can run a python file, part by part, iteratively, like in Jupyter Notebooks, but in .py file.
it helps me to keep the code organized as a python file. (screenshot attached)
I wonder if the same feature exists in PyCharm. I couldn't find it.
I attach a screenshot of the feature in VsCode when I can run simple python file in interactive mode, part by part.
thanks.
The same feature exists in PyCharm.
Just right-click and select Execute selection in Python Console.
ok, answer found:
Magic Python in PyCharm
PyCharm supports Magic Python cell execution. To use Magic Python, you need to enable Scientific Mode in the View menu. You can then use #%% to indicate the start and end of cells. Individual Cells can be executed in the console by pressing CTRL+Enter.
In PyCharm, right-click on the root directory and select New > Python File. Give your file a meaningful name.
Enter
#%%
print("This is the first cell")
#%%
print("This is not executed when the first cell is run")
Enable Scientific Mode in the View menu.
Run the first cell by placing you mouse in the cell and pressing CTRL+Enter.
Run the second cell by clicking on the Play button (arrow) that appears in the gutter of the editor.
source(and credit to):
https://www.kevinsheppard.com/teaching/python/course/lesson-1/
Is there a way to customize (e.g., JSON config) the 'Python Interactive' Window to iPython/Jupyter console that comes with the MS Python extension?
I would like to be able to adjust the size of the variable explorer pane within the window (it can't currently be resized and takes up a bit of screen space.
I would also like the iPython console to look/operate like the native iPython console. That is, have an open console and be able to submit commands just by hitting enter (vs. the default shift+enter). Ideally, I'd like to be able to have it look/operate like Spyder's interactive console. Any thoughts or ideas would be appreciated.
As a workaround I can launch an iPython session from the integrated terminal then select all code from the editor and send it to the terminal (which then gets sent into iPython), but this is not ideal and loses the advantage of the interactive window and the built-in variable explorer which is very nice! Thanks
I'm a developer on this extension. We don't currently have these customizations that you are looking for. But if you would like to report these as enhancements then you could report them on our github here:
https://github.com/microsoft/vscode-python/issues
That's the best way to get attention for adding a new feature.
I've recently switched to VSCode, and am wondering if there's a way to make the Python Interactive Window from the Jupyter support in VSCode work like the console in Spyder where I just have to select code and press ctrl+enter to send it, without having to create cells everytime.
For now I'm resigned to work with the Terminal until my code is clean and then create a cell when I have reusable code, and would like to just work directly with the PIW.
You can always change the default console setting by:
Opening the Command Palette (⇧⌘P)
Typing "Preferences:Open Settings (JSON)
Edit this line:
"python.dataScience.sendSelectionToInteractiveWindow": false
You should be able to do this with the latest python extension. The select the code you want to execute and press shift-enter. Is that not working?
For me (now) interactive mode runs after setting "jupyter.sendSelectionToInteractiveWindow": true
#FranciscoRZ. You should have seen a popup option for this, but if it didn't come up for you it can just be manually set in VSCode options. Just change this guy here:
Python->Data Science: Send Selection To Interactive Window
That should get you what you are looking for.
OP's Note: Accepting this answer because it will be the right anwser starting with the February release of VS Code Python
If you have the notebook saved as a python percentage script (which is more git friendly)
each "cell" will be delimited by # %% and the default run command is "Shift+Ctrl".
Later once you are working in the interactive window, If you want a particular cell you wrote on the fly to be in you script, there is one button which says "Paste code into file" right next to the recently executed cell in the interactive window.
And in case you are using the notebook for the sake of being able to later export it to html or pdf, once executed in the interactive window, there is an export button as well.
I have been running into a trouble whereby Spyder IPython console is not producing Matplotlib figures as desired. I thought initially that there is something wrong in my code since jupyter notebook gives me the same wrong figures. However, when running the script in Spyder using external terminal the figures are produced as desired. Also, when I run the code in VSC the correct figures are displayed.
So the only option I am left with in Spyder is to use the external terminal to execute the code. However, it is quite a pain every time to run some codes and then manually close the terminal.
I would like to know if there is a way to permanently attach the external terminal inside Spyder? I hate the IPython console when it comes to plotting matplotlib figures!!
(Spyder maintainer here) Sorry but there's no way to dock an external Python terminal inside Spyder.
I am using matplotlib.pyplot (with Eclipse on Windows). Every time I run my code it opens several pyplot figure windows.
The problem is that if I don't close those windows manually they accumulate. I would like to use pyplot to find those windows (opened by another process of python.exe) and re-use them. In other words, I do not want to have multiple windows for the same figure, even across interpreter processes.
Is there a simple way to do it?
There is no simple way to reuse plot windows if you must use eclipse to run it. When I am working interactively with matplotlib, I use either spyder or ipython. Edit class, reload class, and run code again. If you just want to get rid of all the open plot windows, hit the stacked stop icons to kill all your runing python instances.