Automatically cleaning the plot pane in Python Spyder - python

I would like to delete all the plots in the plot pane with some code so I can automatically "clear" the interface. I am aware there is a button you can click that deletes them all. However, I would like to avoid having to click manually on the plot pane to delete all the plots generated in the previous runs.
Right now I am already clearing the console and the variable explorer by using (which I got from link):
try:
from IPython import get_ipython
get_ipython().magic('clear')
get_ipython().magic('reset -f')
except:
pass
Now I would like to add there something that also clears the plot pane.

(Spyder maintainer here) It is not possible to remove all plots from the Plots pane using code, sorry.

Related

Boketh plot hide html site and show output only in Jupyter?

With the bokeh package, I created a graph visualization and with show(plot) the output is shown in Jupyter but also at the same time a new tab in the browser is opened with the output. I only want to plot it in a Jupyter cell without opening the plot as a new html file. Is this somehow possible?
#Booketh plot
output_file("thisisaplot.html")
show(plot)
According to the documentation, you should be able to do that by calling output_notebook() before calling show().
Note: As pointed out by #bigreddot, if you were using output_file in the kernel, changing to output_notebook may not take place right away. You will need to either call reset_output(), or restart your kernel for the change to take place.

Spyder: refresh existing plot window instead of opening a new one

I want to show plots in a separate window. Currently I have the IPython graphics backend set to "automatic".
When I re-run the code (or plot another figure), Spyder opens a new plot window. Is it possible to refresh the figure in the window that is already opened instead of opening a new one?
The GUI window that opens when you call plt.show() is bound to a figure. You cannot change the figure inside it. (Well, to be precise, there might be an option of obtaining a handle from the operating system and manipulating its content, but I assume this is not worth the effort.)
Re-running the code actually means that you produce a new figure since the code does not know that it's been run before.
So, exchanging the figure or reusing the window to plot a different figure is not possible.
What is possible however is to use the figure and manipulate the figure while it's open. This is done via plt.ion(). After calling this command in IPython you can adapt the figure, e.g. adding new lines to it etc.
See this example:
At IN [6] the window opens and when IN [7] is executed, the figure stays open and the content changes.
Sure, it is possible with Spyder while in the same running kernel. Try the following example using num as parameter to plt.figure(), where num will always refer to the same figure and refresh it if already opened. Also works with plt.subplots().
import matplotlib.pyplot as plt
from scipy import *
t = linspace(0, 0.1,1000)
w = rand(1)*60*2*pi
fig = plt.figure(num=10, clear=True, figsize = [10,8])
plt.plot(t,cos(w*t))
plt.plot(t,cos(w*t-2*pi/3))
plt.plot(t,cos(w*t-4*pi/3))

PyCharm - always show inspections

PyCharm displays little bars on the scroll bar for things like code warnings. This feature is called "inspection".
If you move the mouse cursor over a bar, it shows a preview of the code annotated with the inspection.
I find this really fiddly, and I'd actually like full inspection notices to be displayed all the time in the normal editor, just like it appears in the small preview.
Is there any way I can achieve this?
Using the default keymap, you can use F2 to jump to the next highlighted error and then Ctrl+F1 to show the tooltip.
According to this PyCharm's documentation there seems to be an Inspection Tool Window which displays inspection results on separate tabs..
You can access the tool window through menu Code | Inspect Code.
I just tried it and it showed a tab like this:
Press Alt+6
Or, click "Problems" on the bottom-left
Or click the error icons at the top-right of the text editor.
This gives a list of problems for the file open in the currently active tab. It automatically updates when you change tabs:

how to get on hover animation of pygal graphs in ipython on mac osx

I have just started using pygal in ipython after installing CairoSVG with pip and Cairo with homebrew.
The graphs render but when I hover over them there is no interactivity (displaying the frequency for a single bar on a bar graph for example)?
What do I need to install to achieve the same rollover/hover functionality that can be seen in the Pygal Documentation?
http://www.pygal.org/en/latest/documentation/first_steps.html
For example when you click on a legend item on a graph, the legend item is greyed out and hidden. Clicking the legend item again makes it return. When I create the sample First Steps code in Ipython and click on a legend item it doesn't disappear.
I stumbled across this issue today. It's the result of a slight typo in the pygal config file.
Fortunately it's simple to fix. Open the config.py file in the pygal directory and add http to the kozea github url as follows:
js = Key(
('http://kozea.github.io/pygal.js/2.0.x/pygal-tooltips.min.js',),
list, "Misc", "List of js file",
"It can be any uri from file:///tmp/ext.js to //domain/ext.js",
str)
That should fix it.
I had the same problem, but after checking the code on git, the better solution would be not to change the config.py file, but instead add
force_uri_protocol='https'
as a parameter to your rendering function, e.g.
chart.render_to_file(output_file, force_uri_protocol='https')

Matplotlib's GUI doesn't allow typing in save box?

I've been using matplotlib in python for some time now and I've finally gotten around to asking this question about an issue on my mac. When a plot shows up (after the plot() command, draw(), or show()), I have all the functionality I could want; I can move, zoom, etc. that I didn't do in the code.
When I go to save a figure with the view as I desire the save as box opens up and prompts for a filename. Anything I type appears in the terminal I used to execute the command! Selecting X11 and then typing has same result. Nothing seems to put the keyboards output into that box, but I can paste into the box using the mouse->Paste action and I can select files in the menu to overwrite and it works fine.
What's up with this?
Update:
The problem was wonderfully outlined and now has some solutions posted in this post: Why doesn't the save button work on a matplotlib plot?
Just installed matplotlib 0.99.1 on Python 2.6.2 on Snow Leopard and ran the following code:
from pylab import *
plot([1,2,3])
show()
Then, I fiddled around with the plot for a while and clicked the save button. The save dialog box popped up normally and allowed me to save (and type) fine. This was using the TkAgg backend. However, I did get this error:
2009-12-08 00:40:18.772 Python[728:60f] -deltaZ is deprecated for NSEventTypeMagnify. Please use -magnification.
Which seems to be something to do with Snow Leopard changing some APIs.
Sorry for using typing this as a post instead of a comment, but code tags aren't allowed in comments :(

Categories