I just started using python. Mostly the output that I have will be 2D-graphs, so I figured matplotlib is the way to go.
When coding I usually position my windows similar to the following screenshot. I assigned hotkeys to these positions using BetterSnapTool on OSX.
Problem is, that I cannot reposition the python output. Instead of the graph, the python notebook will be repositioned. Is there a possible workaround?
[Of course I could manually move the figure every time, but this always costs some time and focus.]
Related
I'm currently using Jupytor Notebook on VSC. I found it very uncomfortable when very long result come out because I have to scroll down a long way to go the the next cell, like shown in the picture.
So I was wondering if there is a way to make the result like the original Jupyter Notebook, where they have a separate scroll for the result as shown below.
As an additional question, anyone know how to search for certain words in the result on VSC? ctrl+f only searches for words in the coding cells and not the result.
A work around for the scroll wheel if you don’t want to collapse the code is to add a print statement to the beginning and end of the code block as mentioned in Collapse Output in VS Code Jupyter Into Scrollable Window. I have not been at my computer to test this and this post is from a year ago, so I’m not sure if this solution is still working. EDIT: This solution is no longer working keep an eye on the linked issue for the resolution.
This was also brought up as an issue on GitHub and it was closed saying they have no plans to work on it currently.
#118117
As for the searching in outputs, this is an open issue currently on GitHub: #94239
Scrollable output regions would be handled in VS Code core. This function has not been decided on GitHub at present
For your additional question, I think the filter feature in the search widget might be what you're looking for - you can include outputs with that.
Looking for a way to figure out the size and position of an active window.
I did search and found solutions that works only on OSX or Windows, but I was not able to find anything that I can use on both platforms, directly from Python.
Do I have to make 2 different implementations for this, or there is a simple way to get window size and position in python, implementing it once?
I've been using the IEP from pyzo before trying out Sublime Text (ST).
There is an annoying behaviour with ST that IEP doesn't have.
In IEP, much like with Matlab or Octave, the editor and the interactive console talk to each other.
Typically if you compute some_stuff and plot it in a script, after execution of this script you can go to the console and check some values:
print some_stuff[0:10]
or modify your plot:
plt.whatever()
which will update your figure.
Also if you run your script several times with different parameters, the figure is simply updated.
However when you do so in ST, even with REPL, after execution of the script nothing is left, you can't access some_stuff[0:10] from REPL. Similarly, you can't modify your figure. And if you run your script several times with different parameters, a new figure is generated in a new window each time instead of updating the existing figure.
Is there an easy work around this? Thanks!
How about saving your figure to a file with plt.savefig("fig.png")? If you open that file with your image viewer it will be updated after running your program.
Is there any way to show a pyplot figure in Python 2.65, Matplotlib 0.99, without locking everything else?
I have a program with a Pmw GUI running on Python 2.75 with Matplotlib 1.3.1. on Windows (64-bit Winpython).
Everytime a figure is drawn (or everytime something is added to an existing one), the routine calls plt.show().
It is possible to show pyplot figures while allowing the user to keep using the GUI and manipulate the figures, nothing blocks anything, as I want it to be since I need the user to look at the plots when deciding what to do next in the GUI, and to have several plots next to each other for comparison.
Now, I need to make all of this work on a system with Python 2.65 and Matplotlib 0.99. The behaviour now seems to be that nothing is visible unless plt.show() is called, and then it will block everything until the plot window is closed.
I tried using plt.draw() instead but then the figure does not even show up.
Worse: Some routines who draw into existing figures never get a chance because they can't execute while the figure is being shown, and when they can, the figure is gone already. I cannot wait until the last drawing operation because the graphs are meant to build up incremental, adding information to existing graphs which the user needs to be able to see.
I am not allowed to update matplotlib. I am allowed to use non-binary parts of libraries if I make them part of "my" software package.
Ideally, I am looking for code that will work in both environments I'm working in, but at this point I am willing to make compromises...
Update:
I have found some code running in the same environment that is able to do all of these things, where I can remove the plt.show() calls, even run it in IDLE (which according to matplotlib docs has problems in these regards), and it "just works" -- I haven't been able to find any difference in how the two codes handle the task: Both define a figure.axes object, pass it to routines that draw into them (using plt.plot()) and store it for future use.
I've also found that my current code will change its behaviour on the current set of libraries, depending on how I run it: In a "regular" console in Spyder or a system console, all's fine, but on a dedicated console in Spyder, the first plot will lock up the interface
=> I'm beginning to think this isn't about the matplotlib version after all, but have no idea where else to look --is there anything else that changes matplotlib's behaviour, based on how it's launched?
It looks like you are looking for:
plt.show(block=False)
or plt.ion:
plt.ion()
plt.show()
# update figure, calc stuff
plt.pause()
Not really sure if they are available in 0.99.
elyase's answer sent me into the right direction:
import matplotlib
matplotlib.interactive(True)
This at the beginning of a script is what it takes to make sure that matplotlib will always and in all environments create plots in a way that allows scripts to continue running, while allowing the user to manipulate the figure and the code to keep drawing into it.
Matplotlib has two modes of operating: The interactive and the non-interactive, and my script going into the latter mode was the problem.
I have still no idea why this is the default behaviour in some cases and not in others (had believed it was one standard setting per matplotlib installation). Since other scripts are able to run without the above. and there must be something that my script inadvertently does to land in non-interactive mode, but the above code is what will override the setting, come what may; at least in all scenarios I've tried so far: python 2.75, matplotlib 1.3.1 using Spyder's regular and dedicated shells and system shells, and Py 2.65, matplotlib 0.99, using system shells and IDLE.
P.S.:
This does not seem to help on Linux. I tried to run the same skript (Tkinter GUI that opens plots, is able to draw into existing plots) on SuSE 13.1 (current version of python 2.7 and all libraries) and no single plot window pops up until the GUI is closed, and then they all jump at me ... it seems that it's not trivial to make matplotlib behave the same everywhere.
I am trying to make an animation with matplotlib in python (2.7) with 3 subplots. To see how this works I tried to understand the example on matplolib.org:
http://matplotlib.org/examples/animation/subplots.html
However when I run this program I only see one of the three plots displayed. Sometimes its the upper right one, sometimes the lower right one.
In my own code I also only see one of the three displayed. Does anyone know if this is a problem with Enthought Canopy and how to fix this?.
Solved, if you set in canopy: preferences > python > PyLab backend: interactive (wx), for some reason it works.