|
From: steve s. <el...@gm...> - 2005-04-27 17:39:51
|
Hi I like MPL very much since I'm used to MATLAB and it's fantastic plotting features but I have 3 little issues (most likely newbie stuff :) to solve. 1.) To change the backend interactively the MPL homepage suggests something like import matplotlib from pylab import * matplotlib.use(<backend-name-string>) plot(...); show() But I found that whatever backend I tell MPL to use, it always uses the one defined in my .matplotlibrc. 2.) When I start my Python shell (IPython, WinXP) and use MPL the 1st time in the session from pylab import * plot(...); show() the plot window appears but I'm not able to type anything in the shell. I close the plot window and plot(...); show() again. From now on I'm able to type in the shell. What's up? 3.) I tried to plot a data set with 1024 points (shape(x) = shape(y) = (1024,)). plot(x,y) which takes about 4 seconds to build up the plot (at least with the TkAgg backend). This is far to slow for me. What can I do? Cheers, Steve -- Man is the best computer we can put aboard a spacecraft ... and the only one that can be mass produced with unskilled labor. - Wernher von Braun |
|
From: John H. <jdh...@ac...> - 2005-04-27 17:57:44
|
>>>>> "steve" == steve schmerler <el...@gm...> writes:
steve> Hi I like MPL very much since I'm used to MATLAB and it's
steve> fantastic plotting features but I have 3 little issues
steve> (most likely newbie stuff :) to solve.
steve> 1.) To change the backend interactively the MPL homepage
steve> suggests something like
steve> import matplotlib from pylab import *
steve> matplotlib.use(<backend-name-string>) plot(...); show()
First, you need to assess whether you really need to change the
backend interactively. Eg, if you are using tkagg and call
savefig('myfile.eps') # uses ps
savefig('myfile.svg) # uses svg
Ie, matplotlib will do the backend switching for you in the most
common use cases.
Now if you really do need to change the default backend interactively,
use the experimental pylab function switch_backend
http://matplotlib.sf.net/matplotlib.pylab.html#-switch_backend
steve> But I found that whatever backend I tell MPL to use, it
steve> always uses the one defined in my .matplotlibrc.
matplotlib.use must be called before the pylab import, and will have
no effect after the import.
steve> 2.) When I start my Python shell (IPython, WinXP) and use
steve> MPL the 1st time in the session
steve> from pylab import * plot(...); show()
steve> the plot window appears but I'm not able to type anything
steve> in the shell. I close the plot window and
steve> plot(...); show()
steve> again. From now on I'm able to type in the shell. What's
steve> up?
You need to start ipython with -pylab option, and then 1) you do not
need to import pylab and 2) you do not need to call show. ipytohn
will read your rc file and do the right thing. See
http://matplotlib.sourceforge.net/interactive.html
and
http://matplotlib.sourceforge.net/faq.html#SHOW
and the ipython manual.
steve> 3.) I tried to plot a data set with 1024 points (shape(x)
steve> = shape(y) = (1024,)).
steve> plot(x,y)
steve> which takes about 4 seconds to build up the plot (at least
steve> with the TkAgg backend). This is far to slow for me. What
steve> can I do?
Are you running on a 486? :-) Are you properly measuring the plot
times versus startup times for python, etc? Maybe the fact that you
are mixing up interactive and non-interactive commands above is
causing you some problems? On my system, to plot 1024 circles takes
0.07 seconds for gtkagg and 0.18 seconds for tkagg. This time
includes creating the new x and y arrays on each iteration as well as
plotting them.
Here is the script I measured these times with , which I ran from
ipython using 'run myscript.py'
import pylab
import time
pylab.ion()
start = time.time()
fig = pylab.figure()
N = 20
for i in range(20):
fig.clear()
ax = fig.add_subplot(111)
x = pylab.rand(1024)
y = pylab.rand(1024)
ax.plot(x, y, 'o')
pylab.draw()
print (time.time() - start)/N
pylab.show()
I'm running on a 3GHz Pentium 4 under linux.
JDH
|
|
From: <Fer...@co...> - 2005-04-27 23:24:40
|
Quoting John Hunter <jdh...@ni...>: > >>>>> "steve" == steve schmerler <el...@gm...> writes: > steve> 2.) When I start my Python shell (IPython, WinXP) and use > steve> MPL the 1st time in the session > > steve> from pylab import * plot(...); show() > > steve> the plot window appears but I'm not able to type anything > steve> in the shell. I close the plot window and > steve> plot(...); show() > > steve> again. From now on I'm able to type in the shell. What's > steve> up? > > You need to start ipython with -pylab option, and then 1) you do not > need to import pylab and 2) you do not need to call show. ipytohn > will read your rc file and do the right thing. See Just to clarify, if you are running a script via ipython's %run, you do need to call show() at the end. That's precisely the conscious change John referred to recently in another thread. Best, f |
|
From: Darren D. <dd...@co...> - 2005-04-27 18:01:58
|
Hi Steve, On Wednesday 27 April 2005 1:39 pm, steve schmerler wrote: > Hi > > I like MPL very much since I'm used to MATLAB and it's fantastic plotting > features but I have 3 little issues (most likely newbie stuff :) to solve. > > 1.) > To change the backend interactively the MPL homepage suggests something > like > > import matplotlib > from pylab import * > matplotlib.use(<backend-name-string>) > plot(...); show() > > But I found that whatever backend I tell MPL to use, it always uses the one > defined in my .matplotlibrc. > If you saw this on the website, it is an error. (I could not find it myself.) You need to do import matplotlib matplotlib.use(<backend-name-string>) from pylab import * plot(...); show() > > 2.) > When I start my Python shell (IPython, WinXP) and use MPL the 1st time in > the session > > from pylab import * > plot(...); show() > > the plot window appears but I'm not able to type anything in the shell. I > close the plot window and > > plot(...); show() > > again. From now on I'm able to type in the shell. What's up? This is due to the interactive nature of MPL. By default, interactive mode is off, to improve performance in scripts. Have you looked into IPython as an alternative to the interactive python interpretter? (Its not really a shell, by the way.) If you dont want to use IPython, try this before you import pylab import matplotlib matplotlib.interactive(True) from pylab import * > > > 3.) > I tried to plot a data set with 1024 points (shape(x) = shape(y) = > (1024,)). > > plot(x,y) > > which takes about 4 seconds to build up the plot (at least with the TkAgg > backend). This is far to slow for me. What can I do? I'll have to defer to the MPL overlords on this one, I dont know enough to answer well. -- Darren S. Dale Bard Hall Department of Materials Science and Engineering Cornell University Ithaca, NY. 14850 dd...@co... |