Re: [Matplotlib-users] speeding-up griddata()
Robert Kern wrote: On 2009-07-13 13:20, Robert Cimrman wrote: Hi all, I would like to use griddata() to interpolate a function given at specified points of a bunch of other points. While the method works well, it slows down considerably as the number of points to interpolate to increases. The dependence of time/(number of points) is nonlinear (see the attachment) - it seems that while the Delaunay trinagulation itself is fast, I wonder how to speed-up the interpolation. The docstring says, that it is based on natural neighbor interpolation - how are the neighbors searched? Using the Delaunay triangulation. The natural neighbors of an interpolation point are those points participating in triangles in the Delaunay triangulation whose circumcircles include the interpolation point. The triangle that encloses the interpolation point is found by a standard walking procedure, then the neighboring triangles (natural or otherwise) are explored in a breadth-first search around the starting triangle to find the natural neighbors. I see, thanks for the explanation. The walking procedure is what is described e.g. in [1], right? (summary; starting from a random triangle, a line is made connecting that triangle with the interpolation point, and triangles along that line are probed.) [1] http://www.geom.uiuc.edu/software/cglist/GeomDir/ptloc96.ps.gz Unfortunately, griddata() uses the unstructured-interpolation-points API rather than the more efficient grid-interpolation-points API. In the former, each interpolation point uses the last-found enclosing triangle as the start of the walking search. This works well where adjacent interpolation points are close to each other. This is not the case at the ends of the grid rows. The latter API is smarter and starts a new row of the grid with the triangle from the triangle from the *start* of the previous row rather than the end. I suspect this is largely the cause of the poor performance. Good to know, I will try to pass the points in groups of close points. Does it use the kd-trees like scipy.spatial? I have a very good experience with scipy.spatial performance. Also, is there a way of reusing the triangulation when interpolating several times using the same grid? One would construct a Triangulation() object with the (x,y) data points, get a new NNInterpolator() object using the .nn_interpolator(z) method for each new z data set, and then interpolate your grid on the NNInterpolator. So if the above fails, I can bypass griddata() by using the delaunay module directly, good. thank you, r. -- Enter the BlackBerry Developer Challenge This is your chance to win up to $100,000 in prizes! For a limited time, vendors submitting new applications to BlackBerry App World(TM) will have the opportunity to enter the BlackBerry Developer Challenge. See full prize details at: http://p.sf.net/sfu/Challenge ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] plot a triangular mesh
Ondrej Certik wrote: On Fri, May 22, 2009 at 3:37 PM, Ondrej Certik ond...@certik.cz wrote: Thanks a lot John. I tried that and it does what I want. I just need to convert and probably average my 3 different values at the 3 vertices of the triangle and color the triangle with that color. When I get it working, I'll send you a picture. :) Ok, I made a progress, it seems it's working. Script and picture attached. You can compare to the mayavi plot above, it's almost identical now. It took my some time playing with different parameters of mpl to get here and I think it looks quite good. Still one can see the artefacts though as John predicted, due to mpl not interpolating the triangles. Nice! Just to prod you a bit: If you want to get rid of the hard mayavi dependence of femhub for 3D plots too, you could hack a (perspective/whatever) projection of 3D surface to 2D, remove invisible faces (normal points backwards) and plot the rest by the painter's algorithm (far faces first). r. -- Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT is a gathering of tech-side developers brand creativity professionals. Meet the minds behind Google Creative Lab, Visual Complexity, Processing, iPhoneDevCamp asthey present alongside digital heavyweights like Barbarian Group, R/GA, Big Spaceship. http://www.creativitycat.com ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] 2 simple ??: program exit w/graph, update graph real-time
Ryan May wrote: On Wed, May 6, 2009 at 8:53 AM, Robert Cimrman cimrm...@ntc.zcu.cz wrote: Ryan May wrote: On Wed, May 6, 2009 at 7:57 AM, Robert Cimrman cimrm...@ntc.zcu.cz wrote: Just for the record: Ryan May's example in this thread, that uses pipes, inspired me to try pipes as well, instead of queues (multiprocessing.Pipe instead of Queue) and the hanging problem, i.e. the problem that Ctrl-C interrupted the program, but it had to be killed to stop, disappeared. I can fix the script that I sent in message [1] and provide it, if there is interest. (Currently I have fixed only the version that is within sfepy). I know I'd be interested. With your permission, it might make a nice example as well. Permission granted :) I have sent the script in response to William. Done. I like the fact that with your example, everything is self-contained in a single script. Exactly, the details of starting another python process are hidden, the multiprocessing module is really nice. You might want to add import matplotlib matplotlib.use('GtkAgg') to the script, and remove from Queue import Empty. FYI: I am sending also a more complex example - a Log class used in sfepy, which supports multiple subplots, labels, logarithmic plots etc. The file contains some other support classes too, so that it works standalone. It is not very polished, but it serves its purpose. r. import matplotlib matplotlib.use('GtkAgg') import numpy as nm from multiprocessing import Process, Pipe from matplotlib.ticker import LogLocator, AutoLocator import pylab import gobject def get_default( arg, default, msg_if_none = None ): if arg is None: out = default else: out = arg if (out is None) and (msg_if_none is not None): raise ValueError( msg_if_none ) return out class Struct( object ): def __init__( self, **kwargs ): if kwargs: self.__dict__.update( kwargs ) def __str__( self ): Print instance class, name and items in alphabetical order. ss = %s % self.__class__.__name__ if hasattr( self, 'name' ): ss += :%s % self.name ss += '\n' keys, vals = self.__dict__.keys(), self.__dict__.values() order = nm.argsort(keys) for ii in order: key, val = keys[ii], vals[ii] if issubclass( val.__class__, Struct ): ss += %s:\n%s % (key, val.__class__.__name__) if hasattr( val, 'name' ): ss += :%s % val.name ss += '\n' else: aux = \n + str( val ) aux = aux.replace( \n, \n ); ss += %s:\n%s\n % (key, aux[1:]) return( ss.rstrip() ) def __repr__( self ): ss = %s % self.__class__.__name__ if hasattr( self, 'name' ): ss += :%s % self.name return ss class Output( Struct ): Factory class providing output (print) functions. Example: output = Output( 'sfepy:' ) output( 1, 2, 3, 'hello' ) output.prefix = 'my_cool_app:' output( 1, 2, 3, 'hello' ) def __init__(self, prefix, filename=None, combined=False, **kwargs): Struct.__init__(self, **kwargs) self.prefix = prefix self.set_output(filename, combined) def __call__(self, *argc, **argv): self.output_function(*argc, **argv) def set_output(self, filename=None, combined=False, append=False): Set the output function - all SfePy printing is accomplished by it. If filename is None, output is to screen only, otherwise it is to the specified file, moreover, if combined is True, both the ways are used. Arguments: filename - print into this file combined - print both on screen and into a file append - append to an existing file instead of overwriting it self.level = 0 def output_screen( *argc, **argv ): format = '%s' + ' %s' * (len( argc ) - 1) msg = format % argc if msg.startswith( '...' ): self.level -= 1 print self._prefix + (' ' * self.level) + msg if msg.endswith( '...' ): self.level += 1 def output_file( *argc, **argv ): format = '%s' + ' %s' * (len( argc ) - 1) msg = format % argc if msg.startswith( '...' ): self.level -= 1 fd = open( filename, 'a' ) print fd, self._prefix + (' ' * self.level) + msg fd.close() if msg.endswith( '...' ): self.level += 1 def output_combined( *argc, **argv ): output_screen( *argc, **argv ) output_file( *argc, **argv ) if filename is None: self.output_function = output_screen else: if not append: fd
Re: [Matplotlib-users] 2 simple ??: program exit w/graph, update graph real-time
Robert Cimrman wrote: Hi Ryan, Ryan May wrote: On Thu, Apr 23, 2009 at 4:16 PM, Esmail ebo...@hotmail.com wrote: Ryan May wrote: Try this: http://matplotlib.sourceforge.net/examples/animation/simple_anim_gtk.html (If not gtk, there are other examples there.) Thanks Ryan, that'll give me some idea with regard to the animation, and real-time drawings. Any idea if it's possible to finish a Python program but still have the graph showing? FWIW, I'm doing this under Linux. You'd have to run the plotting in a separate process from the computation. subprocess would let you do that, assuming you can spin off a child task that stays alive when the parent exits. You'd also need to get the computing process to give new results to the child plot, maybe using a pipe (which I think subprocess can handle as well.) This is exactly what I have tried/described in [1], using the multiprocessing module. It sort of works, but I have that hanging problem at the end - maybe somebody jumps in and helps this time :) r. [1] http://www.mail-archive.com/matplotlib-users@lists.sourceforge.net/msg10873.html Just for the record: Ryan May's example in this thread, that uses pipes, inspired me to try pipes as well, instead of queues (multiprocessing.Pipe instead of Queue) and the hanging problem, i.e. the problem that Ctrl-C interrupted the program, but it had to be killed to stop, disappeared. I can fix the script that I sent in message [1] and provide it, if there is interest. (Currently I have fixed only the version that is within sfepy). thanks! r. [1] [Matplotlib-users] plotting in a separate process, 31.03.2009 -- 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 https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] 2 simple ??: program exit w/graph, update graph real-time
Ryan May wrote: On Wed, May 6, 2009 at 7:57 AM, Robert Cimrman cimrm...@ntc.zcu.cz wrote: Just for the record: Ryan May's example in this thread, that uses pipes, inspired me to try pipes as well, instead of queues (multiprocessing.Pipe instead of Queue) and the hanging problem, i.e. the problem that Ctrl-C interrupted the program, but it had to be killed to stop, disappeared. I can fix the script that I sent in message [1] and provide it, if there is interest. (Currently I have fixed only the version that is within sfepy). I know I'd be interested. With your permission, it might make a nice example as well. Permission granted :) I have sent the script in response to William. r. -- 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 https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] 2 simple ??: program exit w/graph, update graph real-time
william ratcliff wrote: I'd like to see it ; Here you are... r. import time from multiprocessing import Process, Pipe from Queue import Empty import numpy as np import pylab import gobject class ProcessPlotter(object): def __init__(self): self.x = [] self.y = [] def terminate(self): pylab.close('all') def poll_draw(self): def call_back(): while 1: if not self.pipe.poll(): break command = self.pipe.recv() if command is None: self.terminate() return False else: self.x.append(command[0]) self.y.append(command[1]) self.ax.plot(self.x, self.y, 'ro') self.fig.canvas.draw() return True return call_back def __call__(self, pipe): print 'starting plotter...' self.pipe = pipe self.fig = pylab.figure() self.ax = self.fig.add_subplot(111) self.gid = gobject.timeout_add(1000, self.poll_draw()) print '...done' pylab.show() class NBPlot(object): def __init__(self): self.plot_pipe, plotter_pipe = Pipe() self.plotter = ProcessPlotter() self.plot_process = Process(target = self.plotter, args = (plotter_pipe,)) self.plot_process.daemon = True self.plot_process.start() def plot(self, finished=False): send = self.plot_pipe.send if finished: send(None) else: data = np.random.random(2) send(data) def main(): pl = NBPlot() for ii in xrange(10): pl.plot() time.sleep(0.5) raw_input('press Enter...') pl.plot(finished=True) if __name__ == '__main__': main() -- 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 https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] 2 simple ??: program exit w/graph, update graph real-time
Hi Ryan, Ryan May wrote: On Thu, Apr 23, 2009 at 4:16 PM, Esmail ebo...@hotmail.com wrote: Ryan May wrote: Try this: http://matplotlib.sourceforge.net/examples/animation/simple_anim_gtk.html (If not gtk, there are other examples there.) Thanks Ryan, that'll give me some idea with regard to the animation, and real-time drawings. Any idea if it's possible to finish a Python program but still have the graph showing? FWIW, I'm doing this under Linux. You'd have to run the plotting in a separate process from the computation. subprocess would let you do that, assuming you can spin off a child task that stays alive when the parent exits. You'd also need to get the computing process to give new results to the child plot, maybe using a pipe (which I think subprocess can handle as well.) This is exactly what I have tried/described in [1], using the multiprocessing module. It sort of works, but I have that hanging problem at the end - maybe somebody jumps in and helps this time :) r. [1] http://www.mail-archive.com/matplotlib-users@lists.sourceforge.net/msg10873.html -- Crystal Reports #45; New Free Runtime and 30 Day Trial Check out the new simplified licensign option that enables unlimited royalty#45;free distribution of the report engine for externally facing server and web deployment. http://p.sf.net/sfu/businessobjects ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] 2 simple ??: program exit w/graph, update graph real-time
Esmail wrote: Robert Cimrman wrote: This is exactly what I have tried/described in [1], using the multiprocessing module. It sort of works, but I have that hanging problem at the end - maybe somebody jumps in and helps this time :) r. [1] http://www.mail-archive.com/matplotlib-users@lists.sourceforge.net/msg10873.html Hi, Sounds interesting, but I get a page not found 404 type error when I follow this link. Strange, it does work for me. Alternatively, just search [Matplotlib-users] plotting in a separate process in google... r. -- Crystal Reports #45; New Free Runtime and 30 Day Trial Check out the new simplified licensign option that enables unlimited royalty#45;free distribution of the report engine for externally facing server and web deployment. http://p.sf.net/sfu/businessobjects ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] 2 simple ??: program exit w/graph, update graph real-time
Ryan May wrote: On Fri, Apr 24, 2009 at 5:52 AM, Esmail ebo...@hotmail.com wrote: Ryan May wrote: Any idea if it's possible to finish a Python program but still have the graph showing? FWIW, I'm doing this under Linux. You'd have to run the plotting in a separate process from the computation. subprocess would let you do that, assuming you can spin off a child task that stays alive when the parent exits. You'd also need to get the computing process to give new results to the child plot, maybe using a pipe (which I think subprocess can handle as well.) Thanks Ryan, I have been meaning to explore Python's threading/multi-processing facilities, so this will provide a good excuse to do so :-) [when I find the time... so much to learn, so little time] I was curious, so I cooked up a quick demo using two scripts. Put them in the same directory and run datasource.py. It's not perfect, and I think the use of raw_input() is a little odd, but it works. Nice! I will try using the subprocess module instead of multiprocessing, as your example works for me. Thanks! r. -- Crystal Reports #45; New Free Runtime and 30 Day Trial Check out the new simplified licensign option that enables unlimited royalty#45;free distribution of the report engine for externally facing server and web deployment. http://p.sf.net/sfu/businessobjects ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] plotting in a separate process
Hi all! I have a long running (non-GUI) python application, that needs to plot some curves and update them in time, as new data are computed. I'm well aware of ezplot, but would like to use a matplotlib-multiprocessing-only solution, as I have already enough dependencies. The best thing I have come so far with is essentially in the attached script (I stripped all unneeded dependencies and fancy stuff). It works quite well in terms that it plots as the data arrive, but I cannot find a way how to stop it cleanly. At the end, it just hangs (Ctrl-C does not help). I would appreciate any hints on what is wrong. There are two classes: NBPlot spawns the new process and feeds it the data, ProcessPlotter is the remote plotter class plotting the data as they arrive. The plot update is done using gobject.timeout_add() according to the matplotlib examples. It can be run as: $ python log.py Best regards and thanks for your suggestions, r. import time from multiprocessing import Process, Queue from Queue import Empty import numpy as np import pylab import gobject class ProcessPlotter(object): def __init__(self): self.x = [] self.y = [] def terminate(self): pylab.close('all') def poll_draw(self): def call_back(): while 1: try: command = self.queue.get_nowait() except Empty: break print command if command is None: self.terminate() return False else: self.x.append(command[0]) self.y.append(command[1]) self.ax.plot(self.x, self.y, 'ro') self.fig.canvas.draw() return True return call_back def __call__(self, queue): print 'starting plotter...' self.queue = queue self.fig = pylab.figure() self.ax = self.fig.add_subplot(111) self.gid = gobject.timeout_add(1000, self.poll_draw()) print '...done' pylab.show() class NBPlot(object): def __init__(self): self.plot_queue = Queue() self.plotter = ProcessPlotter() self.plot_process = Process( target = self.plotter, args = (self.plot_queue,) ) self.plot_process.daemon = True self.plot_process.start() def plot(self, finished=False): put = self.plot_queue.put if finished: put(None) else: data = np.random.random(2) put(data) def main(): pl = NBPlot() for ii in xrange(10): pl.plot() time.sleep(0.5) raw_input() pl.plot(finished=True) if __name__ == '__main__': main() -- ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] findobj in pylab
Eric Firing wrote: Robert Cimrman wrote: Eric Firing wrote: I'm not sure if this is addressing your situation, but the simplest way to adjust all font sizes is to use the rcParams dictionary, either directly or via the matplotlibrc file. If the default font sizes for various items are specified using medium, large, etc, instead of with numerical values in points, then everything can be scaled by changing the single value, font.size, which is the point size corresponding to medium. Yes, this certainly works, but only for future plots, no? Or it works also if a figure already exists and I want to play with the sizes to get something that looks nice? You are correct, it is for future plots, not for interactive experimentation with font sizes. An alternative, though, is to make a very simple script with a test plot using rcParams, run that repeatedly as needed to tune the values, and then use those values when making the plots you want to keep. Yep. That, or accessing the object properties specific for a given figure, as posted in my first message. I am by no means saying that the rcParams way is not sufficient, I just wanted to elaborate a bit on the findobj idea, as an alternative... Thanks for your feedback, r. - Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW! Studies have shown that voting for your favorite open source project, along with a healthy diet, reduces your potential for chronic lameness and boredom. Vote Now at http://www.sourceforge.net/community/cca08 ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] findobj in pylab
John Hunter wrote: On Thu, Jul 3, 2008 at 8:42 AM, John Kitchin [EMAIL PROTECTED] wrote: Thanks Matthias. That is a helpful example. I have been trying to figure out how to recursively examine all the objects in fig to see if there is a particular settable property. It seems like the algorithm has to be recursive so that it goes deep into all the lists, etc. I have not figured out how to know when you have reached the bottom/end of a trail. Such a function would let me set any text property in the whole figure without needing to know if it was a text object, label, legend, etc... maybe that is not as valuable as I think it would be though. This is a good idea, and I just added an artist method findobj in svn that recursively calls get_children and implements a match criteria (class instance or callable filter). There is also a pyplot/pylab wrapper that operates on current figure by default. Here is an example: import numpy as np import matplotlib.pyplot as plt import matplotlib.text as text a = np.arange(0,3,.02) b = np.arange(0,3,.02) c = np.exp(a) d = c[::-1] fig = plt.figure() ax = fig.add_subplot(111) plt.plot(a,c,'k--',a,d,'k:',a,c+d,'k') plt.legend(('Model length', 'Data length', 'Total message length'), 'upper center', shadow=True) plt.ylim([-1,20]) plt.grid(False) plt.xlabel('Model complexity ---') plt.ylabel('Message length ---') plt.title('Minimum Message Length') # match on arbitrary function def myfunc(x): return hasattr(x, 'set_color') for o in fig.findobj(myfunc): o.set_color('blue') # match on class instances for o in fig.findobj(text.Text): o.set_fontstyle('italic') Great! I used to write many such functions for setting font sizes of all elements in a figure. But speaking about the font sizes, one usually wants the title to be in larger font then the axis labels etc. How could something like this be implemented within your general findobj()? Just for the reference, this is how I did it: def setAxesFontSize( ax, size, titleMul = 1.2, labelMul = 1.0 ): size: tick label size, titleMul: title label size multiplicator, labelMul: x, y axis label size multiplicator labels = ax.get_xticklabels() + ax.get_yticklabels() for label in labels: label.set_size( size ) labels = [ax.get_xaxis().get_label(), ax.get_yaxis().get_label()] for label in labels: label.set_size( labelMul * size ) for child in ax.get_children(): if isinstance( child, pylab.Text ): child.set_size( titleMul * size ) Maybe it could be implemented in the sense of: def myfontsizes( x ): Depending on class of x, return also suggested value of the font size. for o, size in fig.findobj( myfontsizes, suggest_value = True ): o.set_size( size ) # Default for suggest_value is False... for o in fig.findobj(text.Text): o.set_fontstyle('italic') What do you think? r. - Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW! Studies have shown that voting for your favorite open source project, along with a healthy diet, reduces your potential for chronic lameness and boredom. Vote Now at http://www.sourceforge.net/community/cca08 ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] findobj in pylab
Eric Firing wrote: I'm not sure if this is addressing your situation, but the simplest way to adjust all font sizes is to use the rcParams dictionary, either directly or via the matplotlibrc file. If the default font sizes for various items are specified using medium, large, etc, instead of with numerical values in points, then everything can be scaled by changing the single value, font.size, which is the point size corresponding to medium. Yes, this certainly works, but only for future plots, no? Or it works also if a figure already exists and I want to play with the sizes to get something that looks nice? r. - Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW! Studies have shown that voting for your favorite open source project, along with a healthy diet, reduces your potential for chronic lameness and boredom. Vote Now at http://www.sourceforge.net/community/cca08 ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] atomic line.set_xdata and set_ydata
Is there a way of simultaneously setting both xdata and ydata of a line? I need to animate a line with varying number of points in each frame. regards, r. - This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] atomic line.set_xdata and set_ydata
John Hunter wrote: On Jan 29, 2008 8:33 AM, Robert Cimrman [EMAIL PROTECTED] wrote: Is there a way of simultaneously setting both xdata and ydata of a line? I need to animate a line with varying number of points in each frame. line.set_data(xdata, ydata) is what you are looking for Great! I did not see that one. r. - This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] setting font size for figure elements
Hi mpl'ers, I have noticed that I keep setting the font size of the figure elements (axes labels, tick labels, title) so often that it would deserve a function, or better an Axes method to do the same. I am aware of the matplotlibrc settings, but I need something to play with after a figure is drawn. Below is my first attempt - is it the right way of doing things? I misuse the fact that the figure title is the only Text child in my figure. r. def setAxesFontSize( ax, size, titleMul = 1.2, labelMul = 1.0 ): size: tick label size, titleMul: title label size multiplicator, labelMul: x, y axis label size multiplicator labels = ax.get_xticklabels() + ax.get_yticklabels() for label in labels: label.set_size( size ) labels = [ax.get_xaxis().get_label(), ax.get_yaxis().get_label()] for label in labels: label.set_size( labelMul * size ) for child in ax.get_children(): if isinstance( child, Text ): child.set_size( titleMul * size ) - This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now http://get.splunk.com/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] tight axis in OO interface
Hello, I am using the OO interface to plot some data in logarithmic y-scale. The data displayed are almost constant but not entirely, see the attached image. In order to see the details, I would like to do something like 'axis( 'image' )' for the yaxis. I have tried to play with axes.set_ylim(), axes.yaxis.set_ticks() but failed utterly. Can anyone help me? For linear scaling, there is no problem - the axes limits are well adjusted without any intervention. thanks, r. - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] spy ignores negative values?
Eric Firing wrote: Robert Cimrman wrote: [...] What could be done, though, is to raise an exception explaining that sparse matrices and the image mode don't like each other; as it is, the function spy3 just dies on asarray (should be st. like asarray( Z.todense() )) (I think it would be Z.toarray().) Yes. Good point. Alternatives would be to automatically switch it to plot mode, with a warning, or to automatically convert it. Probably the former is the better of these two, and maybe your originally suggested exception is best of all. What do you think? I am slightly more for raising the exception: IMHO, people really needing and using sparse matrices convert never to dense ones (they would not fit into memory in most cases); people happy with automatic conversion should use dense matrices from the very beginning - there is no gain in exploiting sparsity for them; people knowing what they are doing can convert explicitly prior to calling spy(). So: +1 raise an exception +0 switch to plot mode (ok, but inconsistent - why I got a plot when I wanted an image?) -10 automatic conversion r. - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] spy ignores negative values?
Eric Firing wrote: Robert Cimrman wrote: Eric Firing wrote: Robert and any other spy users: I have committed to svn a new axes method, spy3, that combines a modification of the functionality of both spy and spy2. I hope you can check it out. If it looks OK, then I would like to simply replace spy and spy2 with this combined version. In that case the pylab interface, which now gives access to spy and spy2, would have a single spy function which would access the new version. My suspicion is that spy is used almost entirely in interactive mode, and probably not by very many people, so that this changeover can be made quickly with little disruption to present users. Attached is a script illustrating the difference in the way spy3 displays a matrix (it matches the way it is printed: first index is row number, second is column number, row number increases down) versus what spy and spy2 do (first index is X, second index is Y). Also attached is the diff for spy3. Users may want to comment in particular on the default for the aspect kwarg. Presently it is set to equal so that the shape of the plot is the shape of the array with square cells. This differs from spy and spy2. The rationale is that it gives the best picture of what the array looks like, including its shape. Thumbs up :), just add the sparse-full matrix switch to the imshow branch too, if possible. But I am happy with it as it is. The sparse-full difference only works with the plot mode; for an image there is no alternative to providing a value for every pixel, so I don't know of any way to optimize it for the case of sparse storage. A polygon collection could be used to achieve the same result in this case. I'm not sure it is a good idea, though, because there would be an advantage of not converting to a regular array only in the case where the array is so large that such a conversion would use a big chunk of memory, and in that case the polygons probably would be less than single-pixel size anyway, so one would be better off using the present symbol-plotting mode. Yeah, I have tried to write it myself before I posted this message but found that it probably would not work well - nevertheless I asked :). What could be done, though, is to raise an exception explaining that sparse matrices and the image mode don't like each other; as it is, the function spy3 just dies on asarray (should be st. like asarray( Z.todense() )) In [1]:import numpy as nm In [2]:import scipy.sparse as sp In [3]:a = nm.array( [[0, 1], [0,1], [2,3]] ) In [4]:b = sp.csr_matrix( a ) In [5]:gca().spy3( b ) --- exceptions.TypeError Traceback (most recent call last) /home/eldaran/console /usr/lib/python2.4/site-packages/matplotlib/axes.py in spy3(self, Z, precision, marker, markersize, aspect, **kwargs) 4377 4378 if marker is None and markersize is None: - 4379 Z = asarray(Z) 4380 if precision is None: mask = Z!=0. 4381 else: mask = absolute(Z)precision /usr/lib/python2.4/site-packages/numarray/numarraycore.py in asarray(seq, type, typecode, dtype) 432 if isinstance(seq, _gen.NDArray) and type is None and typecode is None: 433 return seq -- 434 return array(seq, type=type, typecode=typecode, copy=0, dtype=dtype) 435 436 inputarray = asarray # Obsolete synonym /usr/lib/python2.4/site-packages/numarray/numarraycore.py in array(sequence, typecode, copy, savespace, type, shape, dtype) 415 if (hasattr(sequence,'__getitem__') 416 and hasattr(sequence,'__len__')): -- 417 return fromlist(sequence,type,shape) 418 419 ##SEQUENCE is a scalar or unhandleable /usr/lib/python2.4/site-packages/numarray/numarraycore.py in fromlist(seq, type, shape, check_overflow, typecode, dtype) 246 return arr 247 -- 248 if not len(seq) and type is None: 249 type = _nt.Long 250 /home/share/software/usr/lib/python2.4/site-packages/scipy/sparse/sparse.py in __len__(self) 163 def __len__(self): 164 # return self.getnnz() -- 165 raise TypeError, sparse matrix length is ambiguous; use getnnz() \ 166 or shape[0] 167 Anyway, I'm glad it works for you. Thanks for checking. Thanks for your fast help! r. - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV ___ Matplotlib-users mailing list Matplotlib-users
Re: [Matplotlib-users] spy ignores negative values?
Eric Firing wrote: Robert and any other spy users: I have committed to svn a new axes method, spy3, that combines a modification of the functionality of both spy and spy2. I hope you can check it out. If it looks OK, then I would like to simply replace spy and spy2 with this combined version. In that case the pylab interface, which now gives access to spy and spy2, would have a single spy function which would access the new version. My suspicion is that spy is used almost entirely in interactive mode, and probably not by very many people, so that this changeover can be made quickly with little disruption to present users. Attached is a script illustrating the difference in the way spy3 displays a matrix (it matches the way it is printed: first index is row number, second is column number, row number increases down) versus what spy and spy2 do (first index is X, second index is Y). Also attached is the diff for spy3. Users may want to comment in particular on the default for the aspect kwarg. Presently it is set to equal so that the shape of the plot is the shape of the array with square cells. This differs from spy and spy2. The rationale is that it gives the best picture of what the array looks like, including its shape. Thumbs up :), just add the sparse-full matrix switch to the imshow branch too, if possible. But I am happy with it as it is. r. - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] spy ignores negative values?
John Hunter wrote: Eric == Eric Firing [EMAIL PROTECTED] writes: Eric Yes, it should be !=0. The purpose is to show how sparse a Eric matrix is--how much is filled with zeros--by displaying the Eric non-zero entries. OK I fixed it. Thanks. Thanks! BTW would you consider changing the definition of spy(2) as shown below, so that one could specify what 'to be a zero' means? r. def spy(self, Z, precision = None, marker='s', markersize=10, **kwargs): if hasattr(Z, 'tocoo'): c = Z.tocoo() if precision is None: x = c.row y = c.col z = c.data else: ii = where( abs( c.data ) precision )[0] x = c.row[ii] y = c.col[ii] z = c.data[ii] else: if precision is None: x,y,z = matplotlib.mlab.get_xyz_where(Z, Z != 0) else: x,y,z = matplotlib.mlab.get_xyz_where(Z, abs( Z ) precision) return self.plot(x+0.5,y+0.5, linestyle='None', marker=marker,markersize=markersize, **kwargs) - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users