scipy.xplt to matplotlib

Hi all,

I am going to switch over to matplotlib.
How can I convert the example with respect to matplotlib ?

from scipy import *
from scipy.xplt import *
import gui_thread
xplt.hold('on')
for t in arange(0,10,0.1):
   xplt.plot(t,sin(t),'g+')
   xplt.pause(10)
   xplt.plot(t,cos(t),'ro')
xplt.xlabel('Time t[s]')
xplt.ylabel('Response')

Nils

Hi all,

I am going to switch over to matplotlib.
How can I convert the example with respect to matplotlib ?

from scipy import *
from scipy.xplt import *
import gui_thread
xplt.hold('on')
for t in arange(0,10,0.1):
  xplt.plot(t,sin(t),'g+')
  xplt.pause(10)
  xplt.plot(t,cos(t),'ro')
xplt.xlabel('Time t[s]')
xplt.ylabel('Response')

import time
from pylab import *
ion()

for t in arange(0, 2, 0.1):
        scatter([t], [sin(t)], color='g', marker='s')
        time.sleep(0.05)
        scatter([t], [cos(t)], color='r', marker='o')
        draw()

xlabel('Time t[s]')
ylabel('Response')
ioff()

show()

This is how I would best approximate what your xplt code does. I'm sure
someone will point out how this could be done better, but psuedo animation
isn't my thing :slight_smile:

If you have a look around in the examples directory of the source
distribution you should be able to find plenty of snippets which give you
a feel for how to write matplotlib code. anim.py is kind of similar to
what you've done here.

Feel free to ask here if you have any other questions.

Cheers,

Tim

Nils

-------------------------------------------------------
This SF.Net email is sponsored by Yahoo.
Introducing Yahoo! Search Developer Network - Create apps using Yahoo!
Search APIs Find out how you can build Yahoo! directly into your own
Applications - visit http://developer.yahoo.net/?fr=offad-ysdn-ostg-q22005
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

`-

···

On Mon, 30 May 2005, Nils Wagner <nwagner@...56...> wrote...

Nils Wagner wrote:

Hi all,

I am going to switch over to matplotlib.
How can I convert the example with respect to matplotlib ?

[~/test]> cat xplot.py
#!/usr/bin/env python
"""xplt-based dynamic plot"""

from scipy import *

xplt.hold('on')
for t in arange(0,10,0.1):
    xplt.plot(t,sin(t),'g+')
    xplt.pause(10)
    xplt.plot(t,cos(t),'ro')
xplt.xlabel('Time t[s]')
xplt.ylabel('Response')

# to prevent the window from closing
raw_input()

[~/test]> cat pplot.py
#!/usr/bin/env python
"""pylab-based dynamic plot"""

from scipy import *

import pylab
pylab.ion() # interactive on, so each plot updates the window

pylab.hold('on')
for t in arange(0,10,0.1):
    pylab.plot([t],[sin(t)],'g+')
    pylab.plot([t],[cos(t)],'ro')
pylab.xlabel('Time t[s]')
pylab.ylabel('Response')

# to prevent the window from closing
raw_input()

···

###

As you can see, all I did was pretty much do xplt->pylab, plus a few very minor changes. The matplotlib website has a lot of documentation, including illustrated screenshots, an examples package, a tutorial and a full user's guide. Since both mpl and xplt were trying to mimic matlab syntax, the transition should be pretty easy for you.

One word of caution: you'll notice that in the above, the xplt script runs very fast, while the mpl one is unacceptably slow (and it consumes a TON of cpu). There may be a trick to provide acceptable update speeds for dynamically resized plots, but unfortunately I don't use that kind of plotting much, so I can't really offer much help there.

I get the feeling that there's an O(N^2) problem somewhere in there, because it seems to me that the plot update slows down worse than linearly as more points are added. But I didn't really measure it, it's just a gut feeling.

Cheers,

f