[matplotlib-devel] new colormap

2006-12-19 Thread Tim Leslie
Hi All,

As part of nipy[1] we have a spectral colormap which we use and would
like to include it upstream as part of matplotlib. I'm working on a
patch but before I submit it, I need some advice on how boilerplate.py
should be used. I've made the required additions to _cm.py, pylab.py
and boilerplate.py and when I run boilerplate.py it generates a
spectral() function as it does for all the other colormaps. My
question is, how should the output of boilerplate.py be included into
pylab.py? Should I just cut and paste the output, or is there some
automagic tool for doing it?

Cheers,

Tim Leslie

[1]  http://neuroimaging.scipy.org/

-
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.php&p=sourceforge&CID=DEVDEV
___
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel


[matplotlib-devel] segfault in dynamic_demo.py

2006-12-19 Thread Tim Leslie
When running examples/dynamic_demo I get a segfault with the following
backtrace. Does anyone have any thoughts on what might be causing
this? I'm using python 2.4 .4c1 and the latest svn version of
mpl/numpy/scipy.

Cheers,

Tim


#0  0x004be54f in PyFrame_New ()
#1  0x00476004 in PyEval_EvalCodeEx ()
#2  0x004bf233 in PyClassMethod_New ()
#3  0x00413bf0 in PyObject_Call ()
#4  0x0046faf1 in PyEval_CallObjectWithKeywords ()
#5  0x2b041ffb412f in init_gobject () from
/var/lib/python-support/python2.4/gtk-2.0/gobject/_gobject.so
#6  0x2b042035218b in g_source_get_current_time () from
/usr/lib/libglib-2.0.so.0
#7  0x2b0420351c84 in g_main_context_dispatch () from
/usr/lib/libglib-2.0.so.0
#8  0x2b0420354acd in g_main_context_check () from /usr/lib/libglib-2.0.so.0
#9  0x2b0420354dda in g_main_loop_run () from /usr/lib/libglib-2.0.so.0
#10 0x2b0420a645f3 in gtk_main () from /usr/lib/libgtk-x11-2.0.so.0
#11 0x2b04295fb601 in wxEventLoop::Run () from
/usr/lib/libwx_gtk2u_core-2.6.so.0
#12 0x2b042968411b in wxAppBase::MainLoop () from
/usr/lib/libwx_gtk2u_core-2.6.so.0
#13 0x2b0428c88487 in wxPyApp::MainLoop () from
/usr/lib/python2.4/site-packages/wx-2.6-gtk2-unicode/wx/_core_.so
#14 0x2b0428ce928f in wxPyFileSystemHandler::FindFirst ()
   from /usr/lib/python2.4/site-packages/wx-2.6-gtk2-unicode/wx/_core_.so
#15 0x00413bf0 in PyObject_Call ()
#16 0x00473fd0 in PyEval_EvalFrame ()
#17 0x004767d6 in PyEval_EvalCodeEx ()
#18 0x004bf233 in PyClassMethod_New ()
#19 0x00413bf0 in PyObject_Call ()
#20 0x00419930 in PyClass_IsSubclass ()
#21 0x00413bf0 in PyObject_Call ()
#22 0x00472619 in PyEval_EvalFrame ()
#23 0x00475546 in PyEval_EvalFrame ()
#24 0x004767d6 in PyEval_EvalCodeEx ()
#25 0x00474a5a in PyEval_EvalFrame ()
#26 0x004767d6 in PyEval_EvalCodeEx ()
#27 0x00476882 in PyEval_EvalCode ()
#28 0x0049b1e2 in PyRun_FileExFlags ()
#29 0x0049b3e0 in PyRun_SimpleFileExFlags ()
#30 0x00410b9a in Py_Main ()
#31 0x2b041fd400c4 in __libc_start_main () from /lib/libc.so.6
#32 0x00410079 in _start ()

-
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.php&p=sourceforge&CID=DEVDEV
___
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel


Re: [matplotlib-devel] new colormap

2006-12-19 Thread Tim Leslie

On 12/20/06, John Hunter <[EMAIL PROTECTED]> wrote:

>>>>> "Tim" == Tim Leslie <[EMAIL PROTECTED]> writes:
Tim> colormaps. My question is, how should the output of
Tim> boilerplate.py be included into pylab.py? Should I just cut
Tim> and paste the output, or is there some automagic tool for
Tim> doing it?

Yep, just cut the stuff below

### Do not edit below this point

and paste in the boilerplate output.


Thanks, that all seems to have worked fine. I've attached the patch
with this email.

John, I was wondering if I have svn write access. I seem to recall I
had it a year or two ago, but I can't find any evidence to back this
up, so maybe I'm mistaken. Could you check for me?

Cheers,

Tim



JDH

Index: lib/matplotlib/_cm.py
===
--- lib/matplotlib/_cm.py	(revision 2941)
+++ lib/matplotlib/_cm.py	(working copy)
@@ -14,6 +14,7 @@
 
 
 
+
 _bone_data = {'red':   ((0., 0., 0.),(1.0, 1.0, 1.0)),
   'green': ((0., 0., 0.),(1.0, 1.0, 1.0)),
   'blue':  ((0., 0., 0.),(1.0, 1.0, 1.0))}
@@ -338,6 +339,41 @@
 'green': ((0., 0., 0.),(1.0, 1.0, 1.0)),
 'blue':  ((0., 1., 1.),(1.0, 0.5, 0.5))}
 
+_spectral_data = {'red': [(0.0, 0.0, 0.0), (0.05, 0.4667, 0.4667),
+  (0.10, 0.5333, 0.5333), (0.15, 0.0, 0.0),
+  (0.20, 0.0, 0.0), (0.25, 0.0, 0.0),
+  (0.30, 0.0, 0.0), (0.35, 0.0, 0.0),
+  (0.40, 0.0, 0.0), (0.45, 0.0, 0.0),
+  (0.50, 0.0, 0.0), (0.55, 0.0, 0.0),
+  (0.60, 0.0, 0.0), (0.65, 0.7333, 0.7333),
+  (0.70, 0.9333, 0.9333), (0.75, 1.0, 1.0),
+  (0.80, 1.0, 1.0), (0.85, 1.0, 1.0),
+  (0.90, 0.8667, 0.8667), (0.95, 0.80, 0.80),
+  (1.0, 0.80, 0.80)],
+  'green': [(0.0, 0.0, 0.0), (0.05, 0.0, 0.0),
+(0.10, 0.0, 0.0), (0.15, 0.0, 0.0),
+(0.20, 0.0, 0.0), (0.25, 0.4667, 0.4667),
+(0.30, 0.6000, 0.6000), (0.35, 0.6667, 0.6667),
+(0.40, 0.6667, 0.6667), (0.45, 0.6000, 0.6000),
+(0.50, 0.7333, 0.7333), (0.55, 0.8667, 0.8667),
+(0.60, 1.0, 1.0), (0.65, 1.0, 1.0),
+(0.70, 0.9333, 0.9333), (0.75, 0.8000, 0.8000),
+(0.80, 0.6000, 0.6000), (0.85, 0.0, 0.0),
+(0.90, 0.0, 0.0), (0.95, 0.0, 0.0),
+(1.0, 0.80, 0.80)],
+  'blue': [(0.0, 0.0, 0.0), (0.05, 0.5333, 0.5333),
+   (0.10, 0.6000, 0.6000), (0.15, 0.6667, 0.6667),
+   (0.20, 0.8667, 0.8667), (0.25, 0.8667, 0.8667),
+   (0.30, 0.8667, 0.8667), (0.35, 0.6667, 0.6667),
+   (0.40, 0.5333, 0.5333), (0.45, 0.0, 0.0),
+   (0.5, 0.0, 0.0), (0.55, 0.0, 0.0),
+   (0.60, 0.0, 0.0), (0.65, 0.0, 0.0),
+   (0.70, 0.0, 0.0), (0.75, 0.0, 0.0),
+   (0.80, 0.0, 0.0), (0.85, 0.0, 0.0),
+   (0.90, 0.0, 0.0), (0.95, 0.0, 0.0),
+   (1.0, 0.80, 0.80)]}
+
+
 autumn = colors.LinearSegmentedColormap('autumn', _autumn_data, LUTSIZE)
 bone   = colors.LinearSegmentedColormap('bone  ', _bone_data, LUTSIZE)
 cool   = colors.LinearSegmentedColormap('cool',   _cool_data, LUTSIZE)
@@ -352,10 +388,10 @@
 spring = colors.LinearSegmentedColormap('spring', _spring_data, LUTSIZE)
 summer = colors.LinearSegmentedColormap('summer', _summer_data, LUTSIZE)
 winter = colors.LinearSegmentedColormap('winter', _winter_data, LUTSIZE)
+spectral = colors.LinearSegmentedColormap('spectral', _spectral_data, LUTSIZE)
 
 
 
-
 datad = {
 'autumn': _autumn_data,
 'bone':   _bone_data,
@@ -370,7 +406,8 @@
 'prism':  _prism_data,
 'spring': _spring_data,
 'summer': _summer_data,
-'winter': _winter_data
+'winter': _winter_data,
+'spectral': _spectral_data
 }
 
 # 34 colormaps based on color specifications and designs
Index: lib/matplotlib/pylab.py
===
--- lib/matplotlib/pylab.py	(revision 2941)
+++ lib/matplotlib/pylab.py	(working copy)
@@ -102,6 +102,7 @@
   spring - set the default colormap to spring
   summer - set the default colormap to summer
   winter - set the default colormap to winter
+  spectral - set the default color

Re: [matplotlib-devel] [Fwd: Re: [Distutils] Confusion about the effect of eggs on import]

2007-02-10 Thread Tim Leslie
On 2/11/07, Gael Varoquaux <[EMAIL PROTECTED]> wrote:
> On Sat, Feb 10, 2007 at 08:04:38AM -0600, John Hunter wrote:
> > I am inclined to consider ripping out the __init__ stuff into a
> > "config" module or something like that.
>
> If my understanding is right, enthought does this with an "api" module.
> It might be worth going in the same direction.
>

And for what it's worth this is also the direction nipy is taking,
having an api.py in each package.

Tim

> My 2 cents,
>
> Gaƫl
>
> --
>   Gael Varoquaux,
>   Groupe d'optique atomique,
>   Laboratoire Charles Fabry de l'Institut d'Optique
>   Campus Polytechnique, RD 128
>   91127 Palaiseau cedex FRANCE
>    NEW Phone number 
>   Tel : 33 (0) 1 64 54 33 49 - Fax : 33 (0) 1 64 54 31 01
>   Labs: 33 (0) 1 64 54 33 63 - 33 (0) 1 64 54 33 62
>
> -
> 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
>

-
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] [Fwd: Re: [Distutils] Confusion about the effect of eggs on import]

2007-02-10 Thread Tim Leslie
On 2/11/07, John Hunter <[EMAIL PROTECTED]> wrote:
> On 2/10/07, Tim Leslie <[EMAIL PROTECTED]> wrote:
>
> > And for what it's worth this is also the direction nipy is taking,
> > having an api.py in each package.
>
> I don't have a problem with this if it makes sense to other people and
> helps with consistency across packages, but I don't find the mnemonic
> particularly clear.  Eg
>
>   from matplotlib.config import rc, verbose
>
> makes more sense to me than
>
>   from matplotlib.api import rc, verbose
>
> since I consider these (and most other stuff in  __init__) to be part
> of the configuration, and a lot of stuff that doesn't live there
> (Figure, Axes, Line2D) to be part of the API.  What is the
> enthought/nipy rationale for calling it api?
>

Sorry, I think I might have given the wrong impression. Our use of an
api.py is for having a single location to import classes equivalent to
Figure, Axes, etc from. Your suggestion of having a matplotlib.config
for things like rc and verbose makes a lot of sense I think.

Tim

> 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


[matplotlib-devel] Two small patches

2007-04-09 Thread Tim Leslie

Hi All,

I've attached a patch which addresses two small issues. The first is a
bug in patches.py. When doing 3d scatter plots

xs, ys = zip(*self.xy) (line 480)

crashes, as the right hand side expands to 3 values.

The other is a speedup, normalising an entire array at once, rather
than element by element, speeding up the attached script by a factor
of 6x (and upgrading my actual application from 'too slow' to 'quite
reasonable' :-)

Cheers,

Tim
Index: lib/matplotlib/art3d.py
===
--- lib/matplotlib/art3d.py	(revision 3193)
+++ lib/matplotlib/art3d.py	(working copy)
@@ -369,7 +369,7 @@
 """Modify the alphas of the color list according to depth"""
 colors = get_colors(colors,len(zs))
 norm = Normalize(min(zs),max(zs))
-sats = nx.array([1-norm(z)*0.7 for z in zs])
+sats = 1 - norm(zs)*0.7 
 colors = [(c[0],c[1],c[2],c[3]*s) for c,s in zip(colors,sats)]
 return colors
 
Index: lib/matplotlib/patches.py
===
--- lib/matplotlib/patches.py	(revision 3193)
+++ lib/matplotlib/patches.py	(working copy)
@@ -480,7 +480,7 @@
 
 
 def get_verts(self):
-xs, ys = zip(*self.xy)
+xs, ys = zip(*self.xy)[:2]
 xs = self.convert_xunits(xs)
 ys = self.convert_yunits(ys)
 return zip(xs, ys)
import random
import pylab as p
import matplotlib.axes3d as p3


def main():
fig = p.figure()
ax = p3.Axes3D(fig)

pts = 7500

X = range(pts)
Y = range(pts)
Z = range(pts)

ax.scatter3D(X, Y, Z)
p.savefig("tmp.png")



if __name__ == '__main__':
import hotshot, hotshot.stats
prof = hotshot.Profile("stones.prof")
benchtime = prof.runcall(main)
prof.close()
stats = hotshot.stats.load("stones.prof")
stats.strip_dirs()
stats.sort_stats('cumulative', 'calls')
stats.print_stats(20)
-
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.php&p=sourceforge&CID=DEVDEV___
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel


Re: [matplotlib-devel] Two small patches

2007-04-09 Thread Tim Leslie
On 4/10/07, John Hunter <[EMAIL PROTECTED]> wrote:
> On 4/9/07, Tim Leslie <[EMAIL PROTECTED]> wrote:
>
> >
> > The other is a speedup, normalising an entire array at once, rather
> > than element by element, speeding up the attached script by a factor
> > of 6x (and upgrading my actual application from 'too slow' to 'quite
> > reasonable' :-)
>
> Thanks Tim, I  just committed this.  I see that my sinister plan of
> releasing the 3d stuff w/o support in hopes of reeling in contributers
> is starting to work

Well I've got a bit of work to do which involves 3D stuff in the
coming week or so, so if I run up against anything else I'll keep the
patches coming. Thanks for the quick commit.

Cheers,

Tim

>
> 
>

-
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.php&p=sourceforge&CID=DEVDEV
___
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel


Re: [matplotlib-devel] Two small patches

2007-04-09 Thread Tim Leslie

On 4/10/07, John Hunter <[EMAIL PROTECTED]> wrote:

On 4/9/07, Tim Leslie <[EMAIL PROTECTED]> wrote:

>
> The other is a speedup, normalising an entire array at once, rather
> than element by element, speeding up the attached script by a factor
> of 6x (and upgrading my actual application from 'too slow' to 'quite
> reasonable' :-)

Thanks Tim, I  just committed this.  I see that my sinister plan of
releasing the 3d stuff w/o support in hopes of reeling in contributers
is starting to work




Here's another patch. This one cleans up the line2d_seg_dist function
and also speeds it up by a factor of ~2.

Cheers,

Tim



Index: proj3d.py
===
--- proj3d.py	(revision 3198)
+++ proj3d.py	(working copy)
@@ -51,52 +51,28 @@
 x0,y0 = p
 return abs((a*x0 + b*y0 + c)/nx.sqrt(a**2+b**2))
 
-def dist2d(p0,p1):
-"""distance between two points"""
-try:
-p = p0-p1
-return nx.sqrt(sum(p**2))
-except ValueError:
-print p0,p1
-raise
 
-def line2d_seg_dist(p0,p1, p):
-"""distance(s) from line defined by p0 - p1 to point(s) p
+def line2d_seg_dist(p1,p2, p0):
+"""distance(s) from line defined by p1 - p2 to point(s) p0
 
-p[0] = x(s)
-p[1] = y(s)
+p0[0] = x(s)
+p0[1] = y(s)
 
-intersection point p = p0 + u*(p1-p0)
+intersection point p = p1 + u*(p2-p1)
 and intersection point lies within segement if u is between 0 and 1
 """
-
-p,p0,p1 = map(nx.asarray,(p[:2],p0[:2],p1[:2]))
-x,y = p
-x0,y0 = p0
-x1,y1 = p1
-# 
-u = ((x-x0)*(x1-x0)+(y-y0)*(y1-y0))/(dist2d(p0,p1)*dist2d(p0,p1))
-#
-def dist(p,p0,p1,u):
-if u > 0 and u < 1:
-pi = p0 + u*(p1-p0)
-return dist2d(p,pi)
-else:
-return nx.minimum(dist2d(p,p0),dist2d(p,p1))
-
-if not iterable(u):
-return dist(p,p0,p1,u)
-else:
-# for each point calculate dist
-pt = nx.transpose(p)
-return nx.array([dist(pe,p0,p1,ue) for pe,ue in zip(pt,u)])
 
-def iterable(v):
-try:
-len(v)
-return True
-except TypeError:
-return False
+x21 = p2[0] - p1[0]
+y21 = p2[1] - p1[1]
+x01 = nx.asarray(p0[0]) - p1[0]
+y01 = nx.asarray(p0[1]) - p1[1]
+
+u = (x01*x21 + y01*y21)/float(abs(x21**2 + y21**2))
+u = nx.clip(u, 0, 1)
+d = nx.sqrt((x01 - u*x21)**2 + (y01 - u*y21)**2)
+
+return d
+
 
 def test_lines_dists():
 ax = pylab.gca()
-
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.php&p=sourceforge&CID=DEVDEV___
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel


[matplotlib-devel] [patch] RegularPolyCollection.get_transformed_patches speed-up

2007-05-09 Thread Tim Leslie

Hi All,

I've attached a patch which optimizes a particular case of the
RegularPolyCollection.get_transformed_patches method. This is
particularly useful when using a picker on a scatter plot with ~40,000
points (as I happen to be doing) and cuts the time spent in this
function from ~4s to ~1s, which accounts for about 50% of the lag in
my particular use case.

Similar improvements might be possible in the N > 1 case, but I don't
have a) a data set or b) the time to work them out with, so hopefully
someone is happy to check in this patch as it stands, as I think the
N==1 is probably the common case.

If there are any problems with the patch let me know and I'll try to
fix it up. It's against latest svn (3262)

Cheers,

Tim
Index: lib/matplotlib/collections.py
===
--- lib/matplotlib/collections.py	(revision 3262)
+++ lib/matplotlib/collections.py	(working copy)
@@ -153,7 +153,7 @@
 if not self.pickable(): return
 ind = []
 x, y = mouseevent.x, mouseevent.y
-for i, thispoly in enumerate(self.get_transformed_patches()):
+for i, thispoly in enumerate(self.get_transformed_patches()):
 inside = nxutils.pnpoly(x, y, thispoly)
 if inside: ind.append(i)
 if len(ind):
@@ -167,7 +167,6 @@
 The ith element in the returned sequence is a list of x,y
 vertices defining the ith polygon
 """
-
 verts = self._verts
 offsets = self._offsets
 usingOffsets = offsets is not None
@@ -451,13 +450,19 @@
 __init__.__doc__ = dedent(__init__.__doc__) % kwdocd
 
 def get_transformed_patches(self):
-
+
 xverts, yverts = zip(*self._verts)
 xverts = asarray(xverts)
 yverts = asarray(yverts)
 sizes = sqrt(asarray(self._sizes)*self._dpi.get()/72.0)
 Nsizes = len(sizes)
 transOffset = self.get_transoffset()
+
+# optimize this case for an approx 4x speedup
+if Nsizes == 1:
+xy = asarray([xverts, yverts]).T * sizes[0]
+polys = [xy + offset for offset in transOffset.seq_xy_tups(self._offsets)]
+
 polys = []
 for i, loc in enumerate(self._offsets):
 xo,yo = transOffset.xy_tup(loc)
-
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/___
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel


Re: [matplotlib-devel] [patch] RegularPolyCollection.get_transformed_patches speed-up

2007-05-09 Thread Tim Leslie
On 5/10/07, Eric Firing <[EMAIL PROTECTED]> wrote:
> Tim,
>
> Based on a *very superficial* quick look, I have two comments:
>
> 1) Since the plan is (or was?) to have one more release before
> specializing to numpy-only support, the ".T" won't work at present.
>
> 2) In the following (possibly mangled by mailer),
>
>  > +if Nsizes == 1:
>  > +xy = asarray([xverts, yverts]).T * sizes[0]
>  > +polys = [xy + offset for offset in
> transOffset.seq_xy_tups(self._offsets)]
>
> I think you can gain additional speedup by eliminating the list
> comprehension.  Instead of using seq_xy_tups you can use numerix_xy to
> return a 2-D array (with columns x and y), and simply add that to xy.
>

Thanks for the feedback Eric, I'll rework the patch with your comments
in mind. I also just noticed a rather glaring bug, in that I don't
actually have a 'return polys' after I calculate them in the special
case, which is somewhat embarrassing. I'll fix all this up and submit
a new patch later today.

Cheers,

Tim

> Eric
>
>
> Tim Leslie wrote:
> > Hi All,
> >
> > I've attached a patch which optimizes a particular case of the
> > RegularPolyCollection.get_transformed_patches method. This is
> > particularly useful when using a picker on a scatter plot with ~40,000
> > points (as I happen to be doing) and cuts the time spent in this
> > function from ~4s to ~1s, which accounts for about 50% of the lag in
> > my particular use case.
> >
> > Similar improvements might be possible in the N > 1 case, but I don't
> > have a) a data set or b) the time to work them out with, so hopefully
> > someone is happy to check in this patch as it stands, as I think the
> > N==1 is probably the common case.
> >
> > If there are any problems with the patch let me know and I'll try to
> > fix it up. It's against latest svn (3262)
> >
> > Cheers,
> >
> > Tim
> >
> >
> > 
> >
> > Index: lib/matplotlib/collections.py
> > ===
> > --- lib/matplotlib/collections.py (revision 3262)
> > +++ lib/matplotlib/collections.py (working copy)
> > @@ -153,7 +153,7 @@
> >  if not self.pickable(): return
> >  ind = []
> >  x, y = mouseevent.x, mouseevent.y
> > -for i, thispoly in enumerate(self.get_transformed_patches()):
> > +for i, thispoly in enumerate(self.get_transformed_patches()):
> >  inside = nxutils.pnpoly(x, y, thispoly)
> >  if inside: ind.append(i)
> >  if len(ind):
> > @@ -167,7 +167,6 @@
> >  The ith element in the returned sequence is a list of x,y
> >  vertices defining the ith polygon
> >  """
> > -
> >  verts = self._verts
> >  offsets = self._offsets
> >  usingOffsets = offsets is not None
> > @@ -451,13 +450,19 @@
> >  __init__.__doc__ = dedent(__init__.__doc__) % kwdocd
> >
> >  def get_transformed_patches(self):
> > -
> > +
> >  xverts, yverts = zip(*self._verts)
> >  xverts = asarray(xverts)
> >  yverts = asarray(yverts)
> >  sizes = sqrt(asarray(self._sizes)*self._dpi.get()/72.0)
> >  Nsizes = len(sizes)
> >  transOffset = self.get_transoffset()
> > +
> > +# optimize this case for an approx 4x speedup
> > +if Nsizes == 1:
> > +xy = asarray([xverts, yverts]).T * sizes[0]
> > +polys = [xy + offset for offset in 
> > transOffset.seq_xy_tups(self._offsets)]
> > +
> >  polys = []
> >  for i, loc in enumerate(self._offsets):
> >  xo,yo = transOffset.xy_tup(loc)
> >
> >
> > 
> >
> > -
> > This SF.net email is sponsored by DB2 Express
> > Download DB2 Express C - the FREE version of DB2 express and take
> > control of your XML. No limits. Just data. Click to get it now.
> > http://sourceforge.net/powerbar/db2/
> >
> >
> > 
> >
> > ___
> > Matplotlib-devel mailing list
> > Matplotlib-devel@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/matplotlib-devel
>
>

-
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
___
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel


Re: [matplotlib-devel] [patch] RegularPolyCollection.get_transformed_patches speed-up

2007-05-10 Thread Tim Leslie
Hi Eric,

I just checked out your change and it works another 0.2s faster than
what I had for my example, so I'm more than happy with the final
result. Thanks for taking the time to put my hazy ideas into practice
the right way :-)

Cheers,

Tim

On 5/10/07, Eric Firing <[EMAIL PROTECTED]> wrote:
> Tim,
>
> I couldn't resist; here is a numerix version of the method, which I
> committed to svn:
>
>  def get_transformed_patches(self):
>  # Shouldn't need all these calls to asarray;
>  # the variables should be converted when stored.
>  # Similar speedups with numerix should be attainable
>  # in many other places.
>  verts = asarray(self._verts)
>  offsets = asarray(self._offsets)
>  Npoly = len(offsets)
>  scales = sqrt(asarray(self._sizes)*self._dpi.get()/72.0)
>  Nscales = len(scales)
>  if Nscales >1:
>  scales = resize(scales, (Npoly, 1, 1))
>  transOffset = self.get_transoffset()
>  xyo = transOffset.numerix_xy(offsets)
>  polys = scales * verts + xyo[:, newaxis, :]
>  return polys
>
> It is faster even when there are only three polygons; and as the comment
> indicates, it would be even faster with additional numpification of the
> entire class.  (Present version with 3 polys, 161 usecs vs 241 usecs;
> with 1000, 6.4 msec vs 47.3 msec.)
>
> It is also only lightly tested.  I hope I haven't overlooked some
> situation that would work with the old version but not with this one.
>
> Eric
>
> Tim Leslie wrote:
> > On 5/10/07, Eric Firing <[EMAIL PROTECTED]> wrote:
> >> Tim,
> >>
> >> Based on a *very superficial* quick look, I have two comments:
> >>
> >> 1) Since the plan is (or was?) to have one more release before
> >> specializing to numpy-only support, the ".T" won't work at present.
> >>
> >> 2) In the following (possibly mangled by mailer),
> >>
> >>  > +if Nsizes == 1:
> >>  > +xy = asarray([xverts, yverts]).T * sizes[0]
> >>  > +polys = [xy + offset for offset in
> >> transOffset.seq_xy_tups(self._offsets)]
> >>
> >> I think you can gain additional speedup by eliminating the list
> >> comprehension.  Instead of using seq_xy_tups you can use numerix_xy to
> >> return a 2-D array (with columns x and y), and simply add that to xy.
> >>
> >
> > Thanks for the feedback Eric, I'll rework the patch with your comments
> > in mind. I also just noticed a rather glaring bug, in that I don't
> > actually have a 'return polys' after I calculate them in the special
> > case, which is somewhat embarrassing. I'll fix all this up and submit
> > a new patch later today.
> >
> > Cheers,
> >
> > Tim
> >
> >> Eric
> >>
> >>
> >> Tim Leslie wrote:
> >> > Hi All,
> >> >
> >> > I've attached a patch which optimizes a particular case of the
> >> > RegularPolyCollection.get_transformed_patches method. This is
> >> > particularly useful when using a picker on a scatter plot with ~40,000
> >> > points (as I happen to be doing) and cuts the time spent in this
> >> > function from ~4s to ~1s, which accounts for about 50% of the lag in
> >> > my particular use case.
> >> >
> >> > Similar improvements might be possible in the N > 1 case, but I don't
> >> > have a) a data set or b) the time to work them out with, so hopefully
> >> > someone is happy to check in this patch as it stands, as I think the
> >> > N==1 is probably the common case.
> >> >
> >> > If there are any problems with the patch let me know and I'll try to
> >> > fix it up. It's against latest svn (3262)
> >> >
> >> > Cheers,
> >> >
> >> > Tim
> >> >
> >> >
> >> >
> >> 
> >> >
> >> > Index: lib/matplotlib/collections.py
> >> > ===
> >> > --- lib/matplotlib/collections.py (revision 3262)
> >> > +++ lib/matplotlib/collections.py (working copy)
> >> > @@ -153,7 +153,7 @@
> >> >  if not self.pickable(): return
> >> >  ind = []
> >> >  x, y = mouseevent.x, mouseevent.y
> >> > -