Re: [matplotlib-devel] custom symbol patch
John Hunter wrote: >> "Manuel" == Manuel Metz <[EMAIL PROTECTED]> writes: > > Manuel> Argh - okay - this is a mistranslation from german to > Manuel> english - sorry. I wanted to say "starlike". So probably > Manuel> StarlikeRegularPolygon is a better name... > > OK, I see. Perhaps we should just call it a StarPolygonCollection > http://en.wikipedia.org/wiki/Star_polygon I've done that. > Also, in your patch, unless I am missing something, it looks like you > could simply do something like > > scale = 0.5/math.sqrt(math.pi) > r = scale*ones(self.numsides*2) > > rather than > > +r = 1.0/math.sqrt(math.pi) # unit area > +r = asarray( [r]*(self.numsides*2) ) > +for i in xrange(1,len(r),2): > +r[i] *= 0.5 > > Ie, do everything in numerix, rather than in python. There is a subtle but essential difference ;-) : for i in xrange(1,len(r), 2 ) ^^^ , i.e. every second value gets rescaled. But there is probably a more "pythonic" way to do that: r = 1.0/math.sqrt(math.pi) # unit area r = asarray( [r,0.5*r]*self.numsides ) I'm not aware of a better way to do this with numerix :-( The patch against the latest svn revision (2810) is attached. Manuel > When you get all of this incorporated, if you could send one patch > against svn that includes all of the changes I'll check it in (if > noone else has any corrections or comments). > > Thanks again, > JDH Index: axes.py === --- axes.py (revision 2810) +++ axes.py (working copy) @@ -15,7 +15,8 @@ from axis import XAxis, YAxis from cbook import iterable, is_string_like, flatten, enumerate, \ allequal, dict_delall, popd, popall, silent_list -from collections import RegularPolyCollection, PolyCollection, LineCollection, QuadMesh +from collections import RegularPolyCollection, PolyCollection, LineCollection, QuadMesh, \ + StarPolygonCollection from colors import colorConverter, normalize, Colormap, \ LinearSegmentedColormap, looks_like_color, is_color_like import cm @@ -1211,7 +1212,7 @@ if xmax is None and hasattr(xmin,'__len__'): xmin,xmax = xmin - old_xmin,old_xmax = self.get_xlim() +old_xmin,old_xmax = self.get_xlim() if xmin is None: xmin = old_xmin if xmax is None: xmax = old_xmax @@ -1223,7 +1224,7 @@ xmin -= 1e-38 xmax += 1e-38 - self.viewLim.intervalx().set_bounds(xmin, xmax) +self.viewLim.intervalx().set_bounds(xmin, xmax) if emit: self._send_xlim_event() return xmin, xmax @@ -1324,7 +1325,7 @@ if ymax is None and hasattr(ymin,'__len__'): ymin,ymax = ymin - old_ymin,old_ymax = self.get_ylim() +old_ymin,old_ymax = self.get_ylim() if ymin is None: ymin = old_ymin if ymax is None: ymax = old_ymax @@ -3100,10 +3101,9 @@ 'h' : hexagon '8' : octagon +If marker is None and verts is not None, verts is a sequence +of (x,y) vertices for a custom scatter symbol. -if marker is None and verts is not None, verts is a sequence -of (x,y) vertices for a custom scatter symbol. The - s is a size argument in points squared. Any or all of x, y, s, and c may be masked arrays, in which @@ -3171,26 +3171,74 @@ if faceted: edgecolors = None else: edgecolors = 'None' -sym = syms.get(marker) -if sym is None and verts is None: -raise ValueError('Unknown marker symbol to scatter') - +sym = None +starlike = False + +if isinstance(marker, str) or isinstance(marker, unicode): +# the standard way to define symbols using a string character +sym = syms.get(marker) +if sym is None and verts is None: +raise ValueError('Unknown marker symbol to scatter') +numsides, rotation = syms[marker] + +# to be API compatible +if sym is None and not (verts is None): +marker = (verts, 0) +verts = None + +if isinstance(marker, tuple) or isinstance(marker, list): +# accept marker to be: +#(numsides, style, [angle]) +# or +#(verts[], style, [angle]) + +if len(marker)<2 or len(marker)>3: +raise ValueError('Cannot create markersymbol from marker') + +if isinstance(marker[0], int) or isinstance(marker[0], long): +# (numsides, style, [angle]) + +if len(marker)==2: +numsides, rotation = marker[0], math.pi/4. +elif len(marker)==3: +numsides, rotation = marker[0], marker[2] +sym = True + +
[matplotlib-devel] GTK Console with inline figures
Hi all, Based on the GTK console bundled with The Gimp I developed a pylab console that display figures inline. I thought it might be of some interest for some of you. A screenshot is available at: http://www.loria.fr/~rougier/pub/Screenshots/pylab-screenshot.png and the console code is at: http://www.loria.fr/~rougier/pub/Softwares/pylab I added a 'replot()' command for re-plotting the last figure. Each time a figure is replot, the previous one is replaced by a (static) image, preventing any further change on it. Nicolas - Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 ___ Matplotlib-devel mailing list Matplotlib-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-devel
Re: [matplotlib-devel] custom symbol patch
> "Manuel" == Manuel Metz <[EMAIL PROTECTED]> writes: Manuel> There is a subtle but essential difference ;-) : for i in Manuel> xrange(1,len(r), 2 ) ^^^ , i.e. every second value gets Manuel> rescaled. But there is probably a more "pythonic" way to Manuel> do that: Manuel> r = 1.0/math.sqrt(math.pi) # unit area r = asarray( Manuel> [r,0.5*r]*self.numsides ) Manuel> I'm not aware of a better way to do this with numerix :-( Oops, sorry I missed that. I think what you want is then scale = 0.5/math.sqrt(math.pi) r = scale*ones(self.numsides*2) r[1::2] *= 0.5 Manuel> The patch against the latest svn revision (2810) is Manuel> attached. OK, if I could make a few more suggestions (I feel like a customer at a restaurant where every time the waiter brings me a cup of coffee I ask "just one more thing"...) +old_ymin,old_ymax = self.get_ylim() The matplotlib style guidelines are UpperCase : classes lower_underscore : functions and methods lower or lowerUpper : variables or attributes For shortish variable names, I prefer oldymin, oldymax = self.get_ylim() +if isinstance(marker, str) or isinstance(marker, unicode): +# the standard way to define symbols using a string character +sym = syms.get(marker) +if isinstance(marker, tuple) or isinstance(marker, list): +# accept marker to be: +#(numsides, style, [angle]) +if isinstance(marker[0], int) or isinstance(marker[0], long): +# (numsides, style, [angle]) Here you should use "duck typing" not "type checking" (google "duck typing"). matplotlib.cbook provides several duck typing functions, eg is_stringlike, iterable and is_numlike. Take a look at is_numlike def is_numlike(obj): try: obj+1 except TypeError: return False else: return True Ie, if it acts like a number (you can add one to it) then we'll treat it as a number. This allows users to provide other integer like classes which are not ints or longs. Everytime you use isinstance, take a 2nd look. There may be a better way. I'll await your updated patch :-) JDH - Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 ___ Matplotlib-devel mailing list Matplotlib-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-devel
Re: [matplotlib-devel] GTK Console with inline figures
> "Nicolas" == Nicolas Rougier <[EMAIL PROTECTED]> writes: Nicolas> Hi all, Nicolas> Based on the GTK console bundled with The Gimp I Nicolas> developed a pylab console that display figures inline. I Nicolas> thought it might be of some interest for some of you. Nicolas> A screenshot is available at: Nicolas> http://www.loria.fr/~rougier/pub/Screenshots/pylab-screenshot.png Nicolas> and the console code is at: Nicolas> http://www.loria.fr/~rougier/pub/Softwares/pylab Nicolas> I added a 'replot()' command for re-plotting the last Nicolas> figure. Each time a figure is replot, the previous one is Nicolas> replaced by a (static) image, preventing any further Nicolas> change on it. Very interesting -- I look forward to testing it. There is a lot of interest in a good GUI shell/IDE for a matlab like environment with python and this looks like it could be a useful piece. FYI, SAGE provides something similar for matplotlib; you may want to take a look at it. Would you consider licensing your code under a more permissive license? Most of the essential scientific computing tools in python (scipy, numpy, matplotlib, ipython, vtk, enthought tool suite, ) are licensed under a BSD-ish style license, and cannot reuse GPLd code. My standard "licensing pitch" is included below:: I'll start by summarizing what many of you already know about open source licenses. I believe this discussion is broadly correct, though it is not a legal document and if you want legally precise statements you should reference the original licenses cited here. The Open-Source-Initiative is a clearing house for OS licenses, so you can read more there. The two dominant license variants in the wild are GPL-style and BSD-style. There are countless other licenses that place specific restrictions on code reuse, but the purpose of this document is to discuss the differences between the GPL and BSD variants, specifically in regards to my experience developing matplotlib and in my discussions with other developers about licensing issues. The best known and perhaps most widely used license is the GPL, which in addition to granting you full rights to the source code including redistribution, carries with it an extra obligation. If you use GPL code in your own code, or link with it, your product must be released under a GPL compatible license. I.e., you are required to give the source code to other people and give them the right to redistribute it as well. Many of the most famous and widely used open source projects are released under the GPL, including linux, gcc and emacs. The second major class are the BSD-style licenses (which includes MIT and the python PSF license). These basically allow you to do whatever you want with the code: ignore it, include it in your own open source project, include it in your proprietary product, sell it, whatever. python itself is released under a BSD compatible license, in the sense that, quoting from the PSF license page There is no GPL-like "copyleft" restriction. Distributing binary-only versions of Python, modified or not, is allowed. There is no requirement to release any of your source code. You can also write extension modules for Python and provide them only in binary form. Famous projects released under a BSD-style license in the permissive sense of the last paragraph are the BSD operating system, python and TeX. I believe the choice of license is an important one, and I advocate a BSD-style license. In my experience, the most important commodity an open source project needs to succeed is users. Of course, doing something useful is a prerequisite to getting users, but I also believe users are something of a prerequisite to doing something useful. It is very difficult to design in a vacuum, and users drive good software by suggesting features and finding bugs. If you satisfy the needs of some users, you will inadvertently end up satisfying the needs of a large class of users. And users become developers, especially if they have some skills and find a feature they need implemented, or if they have a thesis to write. Once you have a lot of users and a number of developers, a network effect kicks in, exponentially increasing your users and developers. In open source parlance, this is sometimes called competing for mind share. So I believe the number one (or at least number two) commodity an open source project can possess is mind share, which means you want as many damned users using your software as you can get. Even though you are giving it away for free, you have to market your software, promote it, and support it as if you were getting paid for it. Now, how does this relate to licensing, you are asking? Many software companies will not use GPL code in their own software, even those that are highly committed to open source development, such as enthought, out of legitimate concern that use of the GPL will "infect" their code base
Re: [matplotlib-devel] GTK Console with inline figures
No problem, I changed the license to a BSD one. Nicolas On Thu, 2006-10-12 at 09:07 -0500, John Hunter wrote: > Very interesting -- I look forward to testing it. There is a lot of > interest in a good GUI shell/IDE for a matlab like environment with > python and this looks like it could be a useful piece. FYI, SAGE > provides something similar for matplotlib; you may want to take a look > at it. > > Would you consider licensing your code under a more permissive > license? Most of the essential scientific computing tools in python > (scipy, numpy, matplotlib, ipython, vtk, enthought tool suite, ) > are licensed under a BSD-ish style license, and cannot reuse GPLd > code. > - Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 ___ Matplotlib-devel mailing list Matplotlib-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-devel
Re: [matplotlib-devel] custom symbol patch
John Hunter wrote: >> "Manuel" == Manuel Metz <[EMAIL PROTECTED]> writes: > > Manuel> There is a subtle but essential difference ;-) : for i in > Manuel> xrange(1,len(r), 2 ) ^^^ , i.e. every second value gets > Manuel> rescaled. But there is probably a more "pythonic" way to > Manuel> do that: > > Manuel> r = 1.0/math.sqrt(math.pi) # unit area r = asarray( > Manuel> [r,0.5*r]*self.numsides ) > > Manuel> I'm not aware of a better way to do this with numerix :-( > > Oops, sorry I missed that. I think what you want is then > > scale = 0.5/math.sqrt(math.pi) > r = scale*ones(self.numsides*2) > r[1::2] *= 0.5 > I've fixed that - and I've learned something ! > > OK, if I could make a few more suggestions (I feel like a customer at > a restaurant where every time the waiter brings me a cup of coffee I > ask "just one more thing"...) > > +old_ymin,old_ymax = self.get_ylim() > > The matplotlib style guidelines are > > UpperCase : classes > lower_underscore : functions and methods > lower or lowerUpper : variables or attributes > > For shortish variable names, I prefer > > oldymin, oldymax = self.get_ylim() Ah - there are three lines that I touched for only one reason: the line indention was done with a "tab" instead of "spaces". When I recognised this in my text editor, I changed it to space-indention. That's the only reason for these patched lines. > +if isinstance(marker, str) or isinstance(marker, unicode): > +# the standard way to define symbols using a string character > +sym = syms.get(marker) > > +if isinstance(marker, tuple) or isinstance(marker, list): > +# accept marker to be: > +#(numsides, style, [angle]) > > +if isinstance(marker[0], int) or isinstance(marker[0], long): > +# (numsides, style, [angle]) > > Here you should use "duck typing" not "type checking" (google "duck > typing"). matplotlib.cbook provides several duck typing functions, eg > is_stringlike, iterable and is_numlike. Take a look at is_numlike > > def is_numlike(obj): > try: obj+1 > except TypeError: return False > else: return True > > Ie, if it acts like a number (you can add one to it) then we'll treat > it as a number. This allows users to provide other integer like > classes which are not ints or longs. Everytime you use isinstance, > take a 2nd look. There may be a better way. > > I'll await your updated patch :-) I've fixed that too - and learned even more ;-) Thanks ! Patch against latest revision is attached. Manuel Index: axes.py === --- axes.py (revision 2811) +++ axes.py (working copy) @@ -14,8 +14,9 @@ from artist import Artist, setp from axis import XAxis, YAxis from cbook import iterable, is_string_like, flatten, enumerate, \ - allequal, dict_delall, popd, popall, silent_list -from collections import RegularPolyCollection, PolyCollection, LineCollection, QuadMesh + allequal, dict_delall, popd, popall, silent_list, is_numlike +from collections import RegularPolyCollection, PolyCollection, LineCollection, QuadMesh, \ + StarPolygonCollection from colors import colorConverter, normalize, Colormap, \ LinearSegmentedColormap, looks_like_color, is_color_like import cm @@ -1211,7 +1212,7 @@ if xmax is None and hasattr(xmin,'__len__'): xmin,xmax = xmin - old_xmin,old_xmax = self.get_xlim() +old_xmin,old_xmax = self.get_xlim() if xmin is None: xmin = old_xmin if xmax is None: xmax = old_xmax @@ -1223,7 +1224,7 @@ xmin -= 1e-38 xmax += 1e-38 - self.viewLim.intervalx().set_bounds(xmin, xmax) +self.viewLim.intervalx().set_bounds(xmin, xmax) if emit: self._send_xlim_event() return xmin, xmax @@ -1324,7 +1325,7 @@ if ymax is None and hasattr(ymin,'__len__'): ymin,ymax = ymin - old_ymin,old_ymax = self.get_ylim() +old_ymin,old_ymax = self.get_ylim() if ymin is None: ymin = old_ymin if ymax is None: ymax = old_ymax @@ -3100,10 +3101,9 @@ 'h' : hexagon '8' : octagon +If marker is None and verts is not None, verts is a sequence +of (x,y) vertices for a custom scatter symbol. -if marker is None and verts is not None, verts is a sequence -of (x,y) vertices for a custom scatter symbol. The - s is a size argument in points squared. Any or all of x, y, s, and c may be masked arrays, in which @@ -3171,26 +3171,74 @@ if faceted: edgecolors = None else: edgecolors = 'None' -sym = syms.get(marker) -if sym is None and verts is None: -raise ValueError('Unknown marker symbol to scatter') - +sym = None +starlike = False + +#
Re: [matplotlib-devel] custom symbol patch
John Hunter wrote: >> >> "Manuel" == Manuel Metz <[EMAIL PROTECTED]> writes: > > > > Manuel> There is a subtle but essential difference ;-) : for i in > > Manuel> xrange(1,len(r), 2 ) ^^^ , i.e. every second value gets > > Manuel> rescaled. But there is probably a more "pythonic" way to > > Manuel> do that: > > > > Manuel> r = 1.0/math.sqrt(math.pi) # unit area r = asarray( > > Manuel> [r,0.5*r]*self.numsides ) > > > > Manuel> I'm not aware of a better way to do this with numerix :-( > > > > Oops, sorry I missed that. I think what you want is then > > > > scale = 0.5/math.sqrt(math.pi) > > r = scale*ones(self.numsides*2) > > r[1::2] *= 0.5 > > I've fixed that - and I've learned something ! > > > > OK, if I could make a few more suggestions (I feel like a customer at > > a restaurant where every time the waiter brings me a cup of coffee I > > ask "just one more thing"...) > > > > +old_ymin,old_ymax = self.get_ylim() > > > > The matplotlib style guidelines are > > > > UpperCase : classes > > lower_underscore : functions and methods > > lower or lowerUpper : variables or attributes > > > > For shortish variable names, I prefer > > > > oldymin, oldymax = self.get_ylim() Ah - there are three lines that I touched for only one reason: the line indention was done with a "tab" instead of "spaces". When I recognised this in my text editor, I changed it to space-indention. That's the only reason for these patched lines. > > +if isinstance(marker, str) or isinstance(marker, unicode): > > +# the standard way to define symbols using a string character > > +sym = syms.get(marker) > > > > +if isinstance(marker, tuple) or isinstance(marker, list): > > +# accept marker to be: > > +#(numsides, style, [angle]) > > > > +if isinstance(marker[0], int) or isinstance(marker[0], long): > > +# (numsides, style, [angle]) > > > > Here you should use "duck typing" not "type checking" (google "duck > > typing"). matplotlib.cbook provides several duck typing functions, eg > > is_stringlike, iterable and is_numlike. Take a look at is_numlike > > > > def is_numlike(obj): > > try: obj+1 > > except TypeError: return False > > else: return True > > > > Ie, if it acts like a number (you can add one to it) then we'll treat > > it as a number. This allows users to provide other integer like > > classes which are not ints or longs. Everytime you use isinstance, > > take a 2nd look. There may be a better way. > > > > I'll await your updated patch :-) I've fixed that too - and learned even more ;-) Thanks ! Patch against latest revision is attached. Manuel Index: axes.py === --- axes.py (revision 2811) +++ axes.py (working copy) @@ -14,8 +14,9 @@ from artist import Artist, setp from axis import XAxis, YAxis from cbook import iterable, is_string_like, flatten, enumerate, \ - allequal, dict_delall, popd, popall, silent_list -from collections import RegularPolyCollection, PolyCollection, LineCollection, QuadMesh + allequal, dict_delall, popd, popall, silent_list, is_numlike +from collections import RegularPolyCollection, PolyCollection, LineCollection, QuadMesh, \ + StarPolygonCollection from colors import colorConverter, normalize, Colormap, \ LinearSegmentedColormap, looks_like_color, is_color_like import cm @@ -1211,7 +1212,7 @@ if xmax is None and hasattr(xmin,'__len__'): xmin,xmax = xmin - old_xmin,old_xmax = self.get_xlim() +old_xmin,old_xmax = self.get_xlim() if xmin is None: xmin = old_xmin if xmax is None: xmax = old_xmax @@ -1223,7 +1224,7 @@ xmin -= 1e-38 xmax += 1e-38 - self.viewLim.intervalx().set_bounds(xmin, xmax) +self.viewLim.intervalx().set_bounds(xmin, xmax) if emit: self._send_xlim_event() return xmin, xmax @@ -1324,7 +1325,7 @@ if ymax is None and hasattr(ymin,'__len__'): ymin,ymax = ymin - old_ymin,old_ymax = self.get_ylim() +old_ymin,old_ymax = self.get_ylim() if ymin is None: ymin = old_ymin if ymax is None: ymax = old_ymax @@ -3100,10 +3101,9 @@ 'h' : hexagon '8' : octagon +If marker is None and verts is not None, verts is a sequence +of (x,y) vertices for a custom scatter symbol. -if marker is None and verts is not None, verts is a sequence -of (x,y) vertices for a custom scatter symbol. The - s is a size argument in points squared. Any or all of x, y, s, and c may be masked arrays, in which @@ -3171,26 +3171,74 @@ if faceted: edgecolors = None else: edgecolors = 'None' -sym = syms.get(marker) -if sym is None and verts is None: -raise Va