From: Fernando P. <Fer...@co...> - 2005-05-30 17:00:34
|
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 |