%run magic and script containing Matplotlib FuncAnimation

22 views
Skip to first unread message

insearcho...@gmail.com

unread,
Jan 15, 2018, 8:31:56 AM1/15/18
to Project Jupyter
I have a bit of a strange issue. 

I have a Matplotlib FuncAnimation that runs correctly in a standalone script in IPython. It also runs correctly if I copy the entire script into a notebook cell and run it after the following magic

    %matplotlib notebook

However, if I use the following two magics

    %matplotlib notebook
    %run myscript.py

the animation does not run correctly. 

I'd prefer to use $run so that I can pass command line arguments to the script.

Any ideas why using the two magics approach would not work, but pasting the entire script into a cell does?

Thomas Kluyver

unread,
Jan 15, 2018, 9:53:18 AM1/15/18
to Project Jupyter
Are you using the two magics in one cell, or over two cells? Some of the effects of the %matplotlib magic may not take effect until the next cell.

--
You received this message because you are subscribed to the Google Groups "Project Jupyter" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jupyter+unsubscribe@googlegroups.com.
To post to this group, send email to jup...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jupyter/26b490aa-3c91-4ec9-b546-4f785f4cab0f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

insearchof answers

unread,
Jan 15, 2018, 11:03:12 AM1/15/18
to jup...@googlegroups.com
I tried it both ways and got the same results. 

In my cell where I pasted the entire script, I have the %matplotlib notebook at the top of that same cell and the script runs correctly. It also runs correctly if I move the  %matplotlib notebook into a cell by itself. 

The only time the script does not work correctly is with %run. It appears that my plt.cla() call (which I need for my particular animation) in each frame is being ignored (or not working correctly) in this case, but it works fine in the cell that contains the entire script. 

--
You received this message because you are subscribed to a topic in the Google Groups "Project Jupyter" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jupyter/xTUys4tzHXU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jupyter+unsubscribe@googlegroups.com.

To post to this group, send email to jup...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages