using MPL and ipython "run" command

Hi all

I'm sure this is documented somewhere, but I can't find it.

I'm finally getting around to learning ipython, which is pathetic as it sure seems like a great tool.

Anyway, I want to be able to have a simple script that does some plotting with MPL, and run it with python's "run". Then change the script and run again, and have the plot updated -- this does not seem to happen. It appears to work if I close th figure by clicking on the Window close button, then "run", but that's kind of a pain.

What am I missing?

example script:

import matplotlib.pyplot as plt
import numpy as np

x = (1,2,3,4,5,6,7,8)
y = (6,2,6,4,6,4,7,5)

plt.plot(x, y)
plt.grid('on')
plt.show()

the I want to be able to do:

In [32]: run test_ipython.py

get a plot, then change some of the numbers in the script and:

In [33]: run test_ipython.py

then get an updated plot.

It's not doing that now.

what am I missing?

thanks,
-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@...259...

Christopher Barker wrote:

Hi all

I'm sure this is documented somewhere, but I can't find it.

I'm finally getting around to learning ipython, which is pathetic as it sure seems like a great tool.

Anyway, I want to be able to have a simple script that does some plotting with MPL, and run it with python's "run". Then change the script and run again, and have the plot updated -- this does not seem to happen. It appears to work if I close th figure by clicking on the Window close button, then "run", but that's kind of a pain.

What am I missing?

Try "ipython -pylab".

Eric

···

example script:

import matplotlib.pyplot as plt
import numpy as np

x = (1,2,3,4,5,6,7,8)
y = (6,2,6,4,6,4,7,5)

plt.plot(x, y)
plt.grid('on')
plt.show()

the I want to be able to do:

In [32]: run test_ipython.py

get a plot, then change some of the numbers in the script and:

In [33]: run test_ipython.py

then get an updated plot.

It's not doing that now.

what am I missing?

thanks,
-Chris

Eric Firing wrote:

What am I missing?

Try "ipython -pylab".

oops, sorry -- I'm already doing that. If I don't do that, then the show() command blocks ipython -- that's not happening, I'm just not getting new plots when it's called again.

thanks,
-Chris

···

Eric

example script:

import matplotlib.pyplot as plt
import numpy as np

x = (1,2,3,4,5,6,7,8)
y = (6,2,6,4,6,4,7,5)

plt.plot(x, y)
plt.grid('on')
plt.show()

the I want to be able to do:

In [32]: run test_ipython.py

get a plot, then change some of the numbers in the script and:

In [33]: run test_ipython.py

then get an updated plot.

It's not doing that now.

what am I missing?

thanks,
-Chris

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@...259...

Hi

You may add these two lines:

fig = plt.figure()
fig.clear()

It should give what you want to see.

Gökhan

···

On Wed, May 6, 2009 at 6:09 PM, Christopher Barker <Chris.Barker@...259...> wrote:

Hi all

I'm sure this is documented somewhere, but I can't find it.

I'm finally getting around to learning ipython, which is pathetic as it
sure seems like a great tool.

Anyway, I want to be able to have a simple script that does some
plotting with MPL, and run it with python's "run". Then change the
script and run again, and have the plot updated -- this does not seem to
happen. It appears to work if I close th figure by clicking on the
Window close button, then "run", but that's kind of a pain.

What am I missing?

example script:

import matplotlib.pyplot as plt
import numpy as np

x = (1,2,3,4,5,6,7,8)
y = (6,2,6,4,6,4,7,5)

plt.plot(x, y)
plt.grid('on')
plt.show()

the I want to be able to do:

In [32]: run test_ipython.py

get a plot, then change some of the numbers in the script and:

In [33]: run test_ipython.py

then get an updated plot.

It's not doing that now.

what am I missing?

thanks,
-Chris

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@...259...

------------------------------------------------------------------------------
The NEW KODAK i700 Series Scanners deliver under ANY circumstances! Your
production scanning environment may not be a perfect world - but thanks to
Kodak, there's a perfect scanner to get the job done! With the NEW KODAK i700
Series Scanner you'll get full speed at 300 dpi even with all image
processing features enabled. http://p.sf.net/sfu/kodak-com
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

Gökhan SEVER wrote:

You may add these two lines:

fig = plt.figure()
fig.clear()

I thought I'd tried that (at least I'd tries plt.clf() ), but indeed, that takes care of it. I'm a bit confused as to why that is necessary, but at least it's working for me.

thanks,
-Chris

···

It should give what you want to see.

Gökhan

On Wed, May 6, 2009 at 6:09 PM, Christopher Barker > <Chris.Barker@...259...> wrote:

Hi all

I'm sure this is documented somewhere, but I can't find it.

I'm finally getting around to learning ipython, which is pathetic as it
sure seems like a great tool.

Anyway, I want to be able to have a simple script that does some
plotting with MPL, and run it with python's "run". Then change the
script and run again, and have the plot updated -- this does not seem to
happen. It appears to work if I close th figure by clicking on the
Window close button, then "run", but that's kind of a pain.

What am I missing?

example script:

import matplotlib.pyplot as plt
import numpy as np

x = (1,2,3,4,5,6,7,8)
y = (6,2,6,4,6,4,7,5)

plt.plot(x, y)
plt.grid('on')
plt.show()

the I want to be able to do:

In [32]: run test_ipython.py

get a plot, then change some of the numbers in the script and:

In [33]: run test_ipython.py

then get an updated plot.

It's not doing that now.

what am I missing?

thanks,
-Chris

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@...259...

------------------------------------------------------------------------------
The NEW KODAK i700 Series Scanners deliver under ANY circumstances! Your
production scanning environment may not be a perfect world - but thanks to
Kodak, there's a perfect scanner to get the job done! With the NEW KODAK i700
Series Scanner you'll get full speed at 300 dpi even with all image
processing features enabled. http://p.sf.net/sfu/kodak-com
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@...259...

I am playing with some other commands to achieve updating on the same
figure, no luck yet.

I guess that is what you actually been trying to see? Update the
figure content without opening another one?

Gökhan

···

On Wed, May 6, 2009 at 6:58 PM, Christopher Barker <Chris.Barker@...259...> wrote:

Gökhan SEVER wrote:

You may add these two lines:

fig = plt.figure()
fig.clear()

I thought I'd tried that (at least I'd tries plt.clf() ), but indeed,
that takes care of it. I'm a bit confused as to why that is necessary,
but at least it's working for me.

thanks,
-Chris

It should give what you want to see.

Gökhan

On Wed, May 6, 2009 at 6:09 PM, Christopher Barker >> <Chris.Barker@...259...> wrote:

Hi all

I'm sure this is documented somewhere, but I can't find it.

I'm finally getting around to learning ipython, which is pathetic as it
sure seems like a great tool.

Anyway, I want to be able to have a simple script that does some
plotting with MPL, and run it with python's "run". Then change the
script and run again, and have the plot updated -- this does not seem to
happen. It appears to work if I close th figure by clicking on the
Window close button, then "run", but that's kind of a pain.

What am I missing?

example script:

import matplotlib.pyplot as plt
import numpy as np

x = (1,2,3,4,5,6,7,8)
y = (6,2,6,4,6,4,7,5)

plt.plot(x, y)
plt.grid('on')
plt.show()

the I want to be able to do:

In [32]: run test_ipython.py

get a plot, then change some of the numbers in the script and:

In [33]: run test_ipython.py

then get an updated plot.

It's not doing that now.

what am I missing?

thanks,
-Chris

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@...259...

------------------------------------------------------------------------------
The NEW KODAK i700 Series Scanners deliver under ANY circumstances! Your
production scanning environment may not be a perfect world - but thanks to
Kodak, there's a perfect scanner to get the job done! With the NEW KODAK i700
Series Scanner you'll get full speed at 300 dpi even with all image
processing features enabled. http://p.sf.net/sfu/kodak-com
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@...259...

------------------------------------------------------------------------------
The NEW KODAK i700 Series Scanners deliver under ANY circumstances! Your
production scanning environment may not be a perfect world - but thanks to
Kodak, there's a perfect scanner to get the job done! With the NEW KODAK i700
Series Scanner you'll get full speed at 300 dpi even with all image
processing features enabled. http://p.sf.net/sfu/kodak-com
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

Christopher Barker wrote:

Gökhan SEVER wrote:

You may add these two lines:

fig = plt.figure()
fig.clear()

I thought I'd tried that (at least I'd tries plt.clf() ), but indeed, that takes care of it. I'm a bit confused as to why that is necessary, but at least it's working for me.

oops, no it doesn't -- what that does is give me a new figure each time, so I get a big stack of them. So I tried:

fig = plt.figure(1)
fig.clear()

then I didn't get a new figure, but I didn't get the figure updated, either -- could this be a back-end bug? I'm using wxAgg, and IIRC, the refreshing code is pretty messed up..

Off to try TK

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@...259...

Gökhan SEVER wrote:

I am playing with some other commands to achieve updating on the same
figure, no luck yet.

I guess that is what you actually been trying to see? Update the
figure content without opening another one?

right.

Christopher Barker wrote:

oops, no it doesn't -- what that does is give me a new figure each time, so I get a big stack of them. So I tried:

fig = plt.figure(1)
fig.clear()

then I didn't get a new figure, but I didn't get the figure updated, either -- could this be a back-end bug? I'm using wxAgg, and IIRC, the refreshing code is pretty messed up..

Off to try TK

OK, with TK, it does refresh when I expect it to. So now to write a new thread, on a wxAgg refresh bug.

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@...259...

Try to put plt.draw() before plt.show().

My guess is that what show() does is to create figure windows, and in
most cases it does not redraw the figure (Tk backend is always an
exception). So, this may not be a bug.
But I hope some who knows well about the backends clarify this.

Regards,

-JJ

···

On Wed, May 6, 2009 at 8:14 PM, Christopher Barker <Chris.Barker@...259...> wrote:

Gökhan SEVER wrote:

I am playing with some other commands to achieve updating on the same
figure, no luck yet.

I guess that is what you actually been trying to see? Update the
figure content without opening another one?

right.

Christopher Barker wrote:

oops, no it doesn't -- what that does is give me a new figure each time,
so I get a big stack of them. So I tried:

fig = plt.figure(1)
fig.clear()

then I didn't get a new figure, but I didn't get the figure updated,
either -- could this be a back-end bug? I'm using wxAgg, and IIRC, the
refreshing code is pretty messed up..

Off to try TK

OK, with TK, it does refresh when I expect it to. So now to write a new
thread, on a wxAgg refresh bug.

-Chris

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@...259...

------------------------------------------------------------------------------
The NEW KODAK i700 Series Scanners deliver under ANY circumstances! Your
production scanning environment may not be a perfect world - but thanks to
Kodak, there's a perfect scanner to get the job done! With the NEW KODAK i700
Series Scanner you'll get full speed at 300 dpi even with all image
processing features enabled. http://p.sf.net/sfu/kodak-com
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

I had a similar issue and this thread mostly solved it, save for one
remaining bug.
If I also call a different module in my main program that does the plotting
in MPL, and then I modify that module, then when I try to run it again in
ipython it acts as if the module I imported has not been changed. If I
change the main program those changes appear, but none of the changes in the
separate module appear.

When I exit ipython and restart everything works normally again, but I would
rather not have to do that every time I edit one of the modules I am
importing.

Any ideas?

Thanks.

Jae-Joon Lee wrote:

···

Try to put plt.draw() before plt.show().

My guess is that what show() does is to create figure windows, and in
most cases it does not redraw the figure (Tk backend is always an
exception). So, this may not be a bug.
But I hope some who knows well about the backends clarify this.

Regards,

-JJ

On Wed, May 6, 2009 at 8:14 PM, Christopher Barker > <Chris.Barker@...259...> wrote:

Gökhan SEVER wrote:

I am playing with some other commands to achieve updating on the same
figure, no luck yet.

I guess that is what you actually been trying to see? Update the
figure content without opening another one?

right.

Christopher Barker wrote:

oops, no it doesn't -- what that does is give me a new figure each time,
so I get a big stack of them. So I tried:

fig = plt.figure(1)
fig.clear()

then I didn't get a new figure, but I didn't get the figure updated,
either -- could this be a back-end bug? I'm using wxAgg, and IIRC, the
refreshing code is pretty messed up..

Off to try TK

OK, with TK, it does refresh when I expect it to. So now to write a new
thread, on a wxAgg refresh bug.

-Chris

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@...259...

------------------------------------------------------------------------------
The NEW KODAK i700 Series Scanners deliver under ANY circumstances! Your
production scanning environment may not be a perfect world - but thanks
to
Kodak, there's a perfect scanner to get the job done! With the NEW KODAK
i700
Series Scanner you'll get full speed at 300 dpi even with all image
processing features enabled. http://p.sf.net/sfu/kodak-com
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

------------------------------------------------------------------------------
The NEW KODAK i700 Series Scanners deliver under ANY circumstances! Your
production scanning environment may not be a perfect world - but thanks to
Kodak, there's a perfect scanner to get the job done! With the NEW KODAK
i700
Series Scanner you'll get full speed at 300 dpi even with all image
processing features enabled. http://p.sf.net/sfu/kodak-com
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

--
View this message in context: http://www.nabble.com/using-MPL-and-ipython-"run"-command-tp23417311p23565347.html
Sent from the matplotlib - users mailing list archive at Nabble.com.