17
17
from colors import colorConverter
18
18
from cm import ScalarMappable
19
19
from numerix import arange , sin , cos , pi , asarray , sqrt , array , newaxis , ones
20
- from numerix import isnan , any
20
+ from numerix import isnan , any , resize
21
21
from transforms import identity_transform
22
22
23
23
import matplotlib .nxutils as nxutils
@@ -141,7 +141,7 @@ def __init__(self,
141
141
#self._offsets = offsets
142
142
self ._offsets = offsets
143
143
self ._transOffset = transOffset
144
- self ._verts = []
144
+ self ._verts = []
145
145
146
146
__init__ .__doc__ = dedent (__init__ .__doc__ ) % kwdocd
147
147
@@ -153,13 +153,13 @@ def pick(self, mouseevent):
153
153
if not self .pickable (): return
154
154
ind = []
155
155
x , y = mouseevent .x , mouseevent .y
156
- for i , thispoly in enumerate (self .get_transformed_patches ()):
156
+ for i , thispoly in enumerate (self .get_transformed_patches ()):
157
157
inside = nxutils .pnpoly (x , y , thispoly )
158
158
if inside : ind .append (i )
159
159
if len (ind ):
160
160
self .figure .canvas .pick_event (mouseevent , self , ind = ind )
161
-
162
-
161
+
162
+
163
163
def get_transformed_patches (self ):
164
164
"""
165
165
get a sequence of the polygons in the collection in display (transformed) space
@@ -348,7 +348,7 @@ def draw(self, renderer):
348
348
transform = self .get_transform ()
349
349
transoffset = self .get_transoffset ()
350
350
351
-
351
+
352
352
transform .freeze ()
353
353
transoffset .freeze ()
354
354
self .update_scalarmappable ()
@@ -364,14 +364,14 @@ def draw(self, renderer):
364
364
transoffset .thaw ()
365
365
renderer .close_group ('polycollection' )
366
366
367
-
367
+
368
368
def get_verts (self , dataTrans = None ):
369
369
'''Return vertices in data coordinates.
370
370
The calculation is incomplete in general; it is based
371
371
on the vertices or the offsets, whichever is using
372
372
dataTrans as its transformation, so it does not take
373
373
into account the combined effect of segments and offsets.
374
- '''
374
+ '''
375
375
verts = []
376
376
if self ._offsets is None :
377
377
for seg in self ._verts :
@@ -451,24 +451,23 @@ def __init__(self,
451
451
__init__ .__doc__ = dedent (__init__ .__doc__ ) % kwdocd
452
452
453
453
def get_transformed_patches (self ):
454
-
455
- xverts , yverts = zip (* self ._verts )
456
- xverts = asarray (xverts )
457
- yverts = asarray (yverts )
458
- sizes = sqrt (asarray (self ._sizes )* self ._dpi .get ()/ 72.0 )
459
- Nsizes = len (sizes )
454
+ # Shouldn't need all these calls to asarray;
455
+ # the variables should be converted when stored.
456
+ # Similar speedups with numerix should be attainable
457
+ # in many other places.
458
+ verts = asarray (self ._verts )
459
+ offsets = asarray (self ._offsets )
460
+ Npoly = len (offsets )
461
+ scales = sqrt (asarray (self ._sizes )* self ._dpi .get ()/ 72.0 )
462
+ Nscales = len (scales )
463
+ if Nscales > 1 :
464
+ scales = resize (scales , (Npoly , 1 , 1 ))
460
465
transOffset = self .get_transoffset ()
461
- polys = []
462
- for i , loc in enumerate (self ._offsets ):
463
- xo ,yo = transOffset .xy_tup (loc )
464
- #print 'xo, yo', loc, (xo, yo)
465
- scale = sizes [i % Nsizes ]
466
-
467
- thisxverts = scale * xverts + xo
468
- thisyverts = scale * yverts + yo
469
- polys .append (zip (thisxverts , thisyverts ))
466
+ xyo = transOffset .numerix_xy (offsets )
467
+ polys = scales * verts + xyo [:, newaxis , :]
470
468
return polys
471
469
470
+
472
471
def _update_verts (self ):
473
472
r = 1.0 / math .sqrt (math .pi ) # unit area
474
473
theta = (2 * math .pi / self .numsides )* arange (self .numsides ) + self .rotation
@@ -486,7 +485,7 @@ def draw(self, renderer):
486
485
self ._update_verts ()
487
486
scales = sqrt (asarray (self ._sizes )* self ._dpi .get ()/ 72.0 )
488
487
489
-
488
+
490
489
offsets = self ._offsets
491
490
if self ._offsets is not None :
492
491
xs , ys = zip (* offsets )
@@ -642,7 +641,7 @@ def __init__(self, segments, # Can be None.
642
641
self ._transOffset = transOffset
643
642
self .set_segments (segments )
644
643
self .update (kwargs )
645
-
644
+
646
645
def get_transoffset (self ):
647
646
if self ._transOffset is None :
648
647
self ._transOffset = identity_transform ()
@@ -678,7 +677,7 @@ def draw(self, renderer):
678
677
679
678
transform .freeze ()
680
679
transoffset .freeze ()
681
-
680
+
682
681
segments = self ._segments
683
682
offsets = self ._offsets
684
683
@@ -693,7 +692,7 @@ def draw(self, renderer):
693
692
xs = self .convert_xunits (self ._offsets [:0 ])
694
693
ys = self .convert_yunits (self ._offsets [:1 ])
695
694
offsets = zip (xs , ys )
696
-
695
+
697
696
self .update_scalarmappable ()
698
697
renderer .draw_line_collection (
699
698
segments , transform , self .clipbox ,
0 commit comments