ipython doesn't update figure while rerun the script on Mac
Question: I haven't been able to find an answer to my question using google, so I will
make a new post here.

I'm using matplotlib with ipython. I'll use a simple script (called a.py) to
demonstrate my question.

    
    
    #/usr/bin/python3
    
    import matplotlib.pyplot as plt
    import numpy as np
    
    x = np.linspace(0, 10, 100)
    y = np.cos(2*x)
    
    plt.plot(x,y)
    plt.show()
    

I can run this script within ipython (started with "ipython --pylab") using
the command "run a.py". It will create a figure window with the right plot.
However, if I modify the code; let's say changing y to np.sin(x), and save the
script. If I run the script again by calling "run a.py", the figure window
doesn't change. No new lines will be added to the figure. Is this a bug or am
I misunderstanding something? I'm new to Python/Ipython/matplotlib.

I'm using Mac OS Yosemite, Python34, py34-ipython, py34-matplotlib. Thanks a
log.

\---- Update -----

If I use plt.savefig("c.pdf") instead of plt.show()

The ipython and the %run command works the way I think it should be; i.e., if
I update the script, and %run a.py again, the changes into the script should
be reflected in the figure.

\--------- More Update --------

One solution I've found is to use command "plt.close()" before any plotting.


Answer: The [`%run`](http://ipython.org/ipython-doc/dev/interactive/magics.html#magic-
run) magic is used to run complete scripts in `ipython`. That's not exactly
what you are trying to do. You may want to have a look at the
[`%load`](http://ipython.org/ipython-doc/dev/interactive/magics.html#magic-
load) magic

In contrast to `%run` which runs scripts, `%load` can be used to pull code
into your current `ipython` session.

  * use `%load a.py`
  * do your modifications and save file `a.py`
  * reuse `%load a.py`

Should do the trick.

