8
8
line segemnts)
9
9
"""
10
10
import math , warnings
11
- from matplotlib import rcParams , verbose
12
-
13
- import artist
14
- from artist import Artist , kwdocd
15
- from backend_bases import GraphicsContextBase
16
- from cbook import is_string_like , iterable , dedent
17
- from colors import colorConverter
18
- from cm import ScalarMappable
19
- from numerix import arange , sin , cos , pi , asarray , sqrt , array , newaxis , ones
20
- from numerix import isnan , any , resize
21
- from transforms import identity_transform
22
-
11
+ import numpy as npy
12
+ import matplotlib as mpl
13
+ import matplotlib .cbook as cbook
14
+ import matplotlib .colors as _colors # avoid conflict with kwarg
15
+ import matplotlib .cm as cm
16
+ import matplotlib .transforms as transforms
17
+ import matplotlib .artist as artist
18
+ import matplotlib .backend_bases as backend_bases
23
19
import matplotlib .nxutils as nxutils
24
20
25
- class Collection (Artist ):
21
+
22
+ class Collection (artist .Artist ):
26
23
"""
27
24
All properties in a collection must be sequences. The
28
25
property of the ith element of the collection is the
@@ -37,7 +34,7 @@ class Collection(Artist):
37
34
"""
38
35
39
36
def __init__ (self ):
40
- Artist .__init__ (self )
37
+ artist . Artist .__init__ (self )
41
38
42
39
43
40
def get_verts (self ):
@@ -47,7 +44,7 @@ def get_verts(self):
47
44
def _get_value (self , val ):
48
45
try : return (float (val ), )
49
46
except TypeError :
50
- if iterable (val ) and len (val ):
47
+ if cbook . iterable (val ) and len (val ):
51
48
try : float (val [0 ])
52
49
except TypeError : pass # raise below
53
50
else : return val
@@ -58,16 +55,16 @@ def _get_value(self, val):
58
55
# these are not available for the object inspector until after the
59
56
# class is built so we define an initial set here for the init
60
57
# function and they will be overridden after object defn
61
- kwdocd ['PatchCollection' ] = """\
58
+ artist . kwdocd ['PatchCollection' ] = """\
62
59
Valid PatchCollection kwargs are:
63
60
64
61
edgecolors=None,
65
62
facecolors=None,
66
63
linewidths=None,
67
64
antialiaseds = None,
68
65
offsets = None,
69
- transOffset = identity_transform(),
70
- norm = None, # optional for ScalarMappable
66
+ transOffset = transforms. identity_transform(),
67
+ norm = None, # optional for cm. ScalarMappable
71
68
cmap = None, # ditto
72
69
73
70
offsets and transOffset are used to translate the patch after
@@ -78,7 +75,7 @@ def _get_value(self, val):
78
75
form.
79
76
"""
80
77
81
- class PatchCollection (Collection , ScalarMappable ):
78
+ class PatchCollection (Collection , cm . ScalarMappable ):
82
79
"""
83
80
Base class for filled regions such as PolyCollection etc.
84
81
It must be subclassed to be usable.
@@ -90,8 +87,8 @@ class PatchCollection(Collection, ScalarMappable):
90
87
linewidths=None,
91
88
antialiaseds = None,
92
89
offsets = None,
93
- transOffset = identity_transform(),
94
- norm = None, # optional for ScalarMappable
90
+ transOffset = transforms. identity_transform(),
91
+ norm = None, # optional for cm. ScalarMappable
95
92
cmap = None, # ditto
96
93
97
94
offsets and transOffset are used to translate the patch after
@@ -123,27 +120,27 @@ def __init__(self,
123
120
%(PatchCollection)s
124
121
"""
125
122
Collection .__init__ (self )
126
- ScalarMappable .__init__ (self , norm , cmap )
123
+ cm . ScalarMappable .__init__ (self , norm , cmap )
127
124
128
- if facecolors is None : facecolors = rcParams ['patch.facecolor' ]
129
- if edgecolors is None : edgecolors = rcParams ['patch.edgecolor' ]
130
- if linewidths is None : linewidths = (rcParams ['patch.linewidth' ],)
131
- if antialiaseds is None : antialiaseds = (rcParams ['patch.antialiased' ],)
125
+ if facecolors is None : facecolors = mpl . rcParams ['patch.facecolor' ]
126
+ if edgecolors is None : edgecolors = mpl . rcParams ['patch.edgecolor' ]
127
+ if linewidths is None : linewidths = (mpl . rcParams ['patch.linewidth' ],)
128
+ if antialiaseds is None : antialiaseds = (mpl . rcParams ['patch.antialiased' ],)
132
129
133
- self ._facecolors = colorConverter .to_rgba_list (facecolors )
130
+ self ._facecolors = _colors . colorConverter .to_rgba_list (facecolors )
134
131
if edgecolors == 'None' :
135
132
self ._edgecolors = self ._facecolors
136
133
linewidths = (0 ,)
137
134
else :
138
- self ._edgecolors = colorConverter .to_rgba_list (edgecolors )
135
+ self ._edgecolors = _colors . colorConverter .to_rgba_list (edgecolors )
139
136
self ._linewidths = linewidths
140
137
self ._antialiaseds = antialiaseds
141
138
#self._offsets = offsets
142
139
self ._offsets = offsets
143
140
self ._transOffset = transOffset
144
141
self ._verts = []
145
142
146
- __init__ .__doc__ = dedent (__init__ .__doc__ ) % kwdocd
143
+ __init__ .__doc__ = cbook . dedent (__init__ .__doc__ ) % artist . kwdocd
147
144
148
145
def pick (self , mouseevent ):
149
146
"""
@@ -186,7 +183,7 @@ def get_transformed_patches(self):
186
183
for i in xrange (N ):
187
184
#print 'i%%Nverts=%d'%(i%Nverts)
188
185
polyverts = verts [i % Nverts ]
189
- if any (isnan (polyverts )):
186
+ if npy . any (npy . isnan (polyverts )):
190
187
continue
191
188
#print 'thisvert', i, polyverts
192
189
tverts = transform .seq_xy_tups (polyverts )
@@ -200,7 +197,7 @@ def get_transformed_patches(self):
200
197
201
198
def get_transoffset (self ):
202
199
if self ._transOffset is None :
203
- self ._transOffset = identity_transform ()
200
+ self ._transOffset = transforms . identity_transform ()
204
201
return self ._transOffset
205
202
206
203
@@ -233,7 +230,7 @@ def set_facecolor(self, c):
233
230
234
231
ACCEPTS: matplotlib color arg or sequence of rgba tuples
235
232
"""
236
- self ._facecolors = colorConverter .to_rgba_list (c )
233
+ self ._facecolors = _colors . colorConverter .to_rgba_list (c )
237
234
238
235
def set_edgecolor (self , c ):
239
236
"""
@@ -243,7 +240,7 @@ def set_edgecolor(self, c):
243
240
244
241
ACCEPTS: matplotlib color arg or sequence of rgba tuples
245
242
"""
246
- self ._edgecolors = colorConverter .to_rgba_list (c )
243
+ self ._edgecolors = _colors . colorConverter .to_rgba_list (c )
247
244
248
245
def set_alpha (self , alpha ):
249
246
"""
@@ -255,9 +252,9 @@ def set_alpha(self, alpha):
255
252
try : float (alpha )
256
253
except TypeError : raise TypeError ('alpha must be a float' )
257
254
else :
258
- Artist .set_alpha (self , alpha )
255
+ artist . Artist .set_alpha (self , alpha )
259
256
self ._facecolors = [(r ,g ,b ,alpha ) for r ,g ,b ,a in self ._facecolors ]
260
- if is_string_like (self ._edgecolors ) and self ._edgecolors != 'None' :
257
+ if cbook . is_string_like (self ._edgecolors ) and self ._edgecolors != 'None' :
261
258
self ._edgecolors = [(r ,g ,b ,alpha ) for r ,g ,b ,a in self ._edgecolors ]
262
259
263
260
def update_scalarmappable (self ):
@@ -336,7 +333,7 @@ def __init__(self, verts, **kwargs):
336
333
"""
337
334
PatchCollection .__init__ (self ,** kwargs )
338
335
self ._verts = verts
339
- __init__ .__doc__ = dedent (__init__ .__doc__ ) % kwdocd
336
+ __init__ .__doc__ = cbook . dedent (__init__ .__doc__ ) % artist . kwdocd
340
337
341
338
def set_verts (self , verts ):
342
339
'''This allows one to delay initialization of the vertices.'''
@@ -352,7 +349,7 @@ def draw(self, renderer):
352
349
transform .freeze ()
353
350
transoffset .freeze ()
354
351
self .update_scalarmappable ()
355
- if is_string_like (self ._edgecolors ) and self ._edgecolors [:2 ] == 'No' :
352
+ if cbook . is_string_like (self ._edgecolors ) and self ._edgecolors [:2 ] == 'No' :
356
353
self ._linewidths = (0 ,)
357
354
#self._edgecolors = self._facecolors
358
355
renderer .draw_poly_collection (
@@ -398,7 +395,7 @@ def __init__(self, xranges, yrange, **kwargs):
398
395
ymax = ymin + ywidth
399
396
verts = [ [(xmin , ymin ), (xmin , ymax ), (xmin + xwidth , ymax ), (xmin + xwidth , ymin )] for xmin , xwidth in xranges ]
400
397
PolyCollection .__init__ (self , verts , ** kwargs )
401
- __init__ .__doc__ = dedent (__init__ .__doc__ ) % kwdocd
398
+ __init__ .__doc__ = cbook . dedent (__init__ .__doc__ ) % artist . kwdocd
402
399
403
400
class RegularPolyCollection (PatchCollection ):
404
401
def __init__ (self ,
@@ -448,30 +445,30 @@ def __init__(self,
448
445
self .numsides = numsides
449
446
self .rotation = rotation
450
447
self ._update_verts ()
451
- __init__ .__doc__ = dedent (__init__ .__doc__ ) % kwdocd
448
+ __init__ .__doc__ = cbook . dedent (__init__ .__doc__ ) % artist . kwdocd
452
449
453
450
def get_transformed_patches (self ):
454
451
# Shouldn't need all these calls to asarray;
455
452
# the variables should be converted when stored.
456
453
# Similar speedups with numerix should be attainable
457
454
# in many other places.
458
- verts = asarray (self ._verts )
459
- offsets = asarray (self ._offsets )
455
+ verts = npy . asarray (self ._verts )
456
+ offsets = npy . asarray (self ._offsets )
460
457
Npoly = len (offsets )
461
- scales = sqrt (asarray (self ._sizes )* self ._dpi .get ()/ 72.0 )
458
+ scales = npy . sqrt (npy . asarray (self ._sizes )* self ._dpi .get ()/ 72.0 )
462
459
Nscales = len (scales )
463
460
if Nscales > 1 :
464
- scales = resize (scales , (Npoly , 1 , 1 ))
461
+ scales = npy . resize (scales , (Npoly , 1 , 1 ))
465
462
transOffset = self .get_transoffset ()
466
463
xyo = transOffset .numerix_xy (offsets )
467
- polys = scales * verts + xyo [:, newaxis , :]
464
+ polys = scales * verts + xyo [:, npy . newaxis , :]
468
465
return polys
469
466
470
467
471
468
def _update_verts (self ):
472
469
r = 1.0 / math .sqrt (math .pi ) # unit area
473
- theta = (2 * math .pi / self .numsides )* arange (self .numsides ) + self .rotation
474
- self ._verts = zip ( r * sin (theta ), r * cos (theta ) )
470
+ theta = (2 * math .pi / self .numsides )* npy . arange (self .numsides ) + self .rotation
471
+ self ._verts = zip ( r * npy . sin (theta ), r * npy . cos (theta ) )
475
472
476
473
def draw (self , renderer ):
477
474
if not self .get_visible (): return
@@ -483,7 +480,7 @@ def draw(self, renderer):
483
480
transoffset .freeze ()
484
481
self .update_scalarmappable ()
485
482
self ._update_verts ()
486
- scales = sqrt (asarray (self ._sizes )* self ._dpi .get ()/ 72.0 )
483
+ scales = npy . sqrt (npy . asarray (self ._sizes )* self ._dpi .get ()/ 72.0 )
487
484
488
485
489
486
offsets = self ._offsets
@@ -499,7 +496,7 @@ def draw(self, renderer):
499
496
#print 'drawing offsets', offsets
500
497
#print 'drawing verts', self._verts
501
498
#print 'drawing scales', scales
502
- if is_string_like (self ._edgecolors ) and self ._edgecolors [:2 ] == 'No' :
499
+ if cbook . is_string_like (self ._edgecolors ) and self ._edgecolors [:2 ] == 'No' :
503
500
#self._edgecolors = self._facecolors
504
501
self ._linewidths = (0 ,)
505
502
renderer .draw_regpoly_collection (
@@ -548,16 +545,17 @@ def __init__(self,
548
545
"""
549
546
550
547
RegularPolyCollection .__init__ (self , dpi , numsides , rotation , sizes , ** kwargs )
551
- __init__ .__doc__ = dedent (__init__ .__doc__ ) % kwdocd
548
+ __init__ .__doc__ = cbook . dedent (__init__ .__doc__ ) % artist . kwdocd
552
549
553
550
def _update_verts (self ):
554
551
scale = 1.0 / math .sqrt (math .pi )
555
- r = scale * ones (self .numsides * 2 )
552
+ ns2 = self .numsides * 2
553
+ r = scale * npy .ones (ns2 )
556
554
r [1 ::2 ] *= 0.5
557
- theta = (2. * math .pi / (2 * self . numsides ))* arange (2 * self . numsides ) + self .rotation
558
- self ._verts = zip ( r * sin (theta ), r * cos (theta ) )
555
+ theta = (2. * math .pi / (ns2 ))* npy . arange (ns2 ) + self .rotation
556
+ self ._verts = zip ( r * npy . sin (theta ), r * npy . cos (theta ) )
559
557
560
- class LineCollection (Collection , ScalarMappable ):
558
+ class LineCollection (Collection , cm . ScalarMappable ):
561
559
"""
562
560
All parameters must be sequences. The property of the ith line
563
561
segment is the prop[i % len(props)], ie the properties cycle if
@@ -566,11 +564,11 @@ class LineCollection(Collection, ScalarMappable):
566
564
zorder = 2
567
565
def __init__ (self , segments , # Can be None.
568
566
linewidths = None ,
569
- colors = None ,
567
+ colors = None ,
570
568
antialiaseds = None ,
571
569
linestyle = 'solid' ,
572
570
offsets = None ,
573
- transOffset = None ,#identity_transform(),
571
+ transOffset = None ,#transforms. identity_transform(),
574
572
norm = None ,
575
573
cmap = None ,
576
574
** kwargs
@@ -590,7 +588,7 @@ def __init__(self, segments, # Can be None.
590
588
solid|dashed|dashdot|dotted. The dash tuple is (offset, onoffseq)
591
589
where onoffseq is an even length tuple of on and off ink in points.
592
590
593
- If linewidths, colors , or antialiaseds is None, they default to
591
+ If linewidths, colors_ , or antialiaseds is None, they default to
594
592
their rc params setting, in sequence form.
595
593
596
594
If offsets and transOffset are not None, then
@@ -613,43 +611,43 @@ def __init__(self, segments, # Can be None.
613
611
"""
614
612
615
613
Collection .__init__ (self )
616
- ScalarMappable .__init__ (self , norm , cmap )
614
+ cm . ScalarMappable .__init__ (self , norm , cmap )
617
615
618
616
if linewidths is None :
619
- linewidths = (rcParams ['lines.linewidth' ], )
617
+ linewidths = (mpl . rcParams ['lines.linewidth' ], )
620
618
621
619
if colors is None :
622
- colors = (rcParams ['lines.color' ],)
620
+ colors = (mpl . rcParams ['lines.color' ],)
623
621
if antialiaseds is None :
624
- antialiaseds = (rcParams ['lines.antialiased' ], )
622
+ antialiaseds = (mpl . rcParams ['lines.antialiased' ], )
625
623
626
- self ._colors = colorConverter .to_rgba_list (colors )
624
+ self ._colors = _colors . colorConverter .to_rgba_list (colors )
627
625
self ._aa = antialiaseds
628
626
self ._lw = linewidths
629
627
self .set_linestyle (linestyle )
630
628
self ._uniform_offsets = None
631
629
if offsets is not None :
632
- offsets = asarray (offsets )
630
+ offsets = npy . asarray (offsets )
633
631
if len (offsets .shape ) == 1 :
634
- offsets = offsets [newaxis ,:] # Make it Nx2.
632
+ offsets = offsets [npy . newaxis ,:] # Make it Nx2.
635
633
if transOffset is None :
636
634
if offsets is not None :
637
635
self ._uniform_offsets = offsets
638
636
offsets = None
639
- transOffset = identity_transform ()
637
+ transOffset = transforms . identity_transform ()
640
638
self ._offsets = offsets
641
639
self ._transOffset = transOffset
642
640
self .set_segments (segments )
643
641
self .update (kwargs )
644
642
645
643
def get_transoffset (self ):
646
644
if self ._transOffset is None :
647
- self ._transOffset = identity_transform ()
645
+ self ._transOffset = transforms . identity_transform ()
648
646
return self ._transOffset
649
647
650
648
def set_segments (self , segments ):
651
649
if segments is None : return
652
- self ._segments = [asarray (seg ) for seg in segments ]
650
+ self ._segments = [npy . asarray (seg ) for seg in segments ]
653
651
if self ._uniform_offsets is not None :
654
652
self ._add_offsets ()
655
653
@@ -720,9 +718,9 @@ def set_linestyle(self, ls):
720
718
Set the linestyles(s) for the collection.
721
719
ACCEPTS: ['solid' | 'dashed', 'dashdot', 'dotted' | (offset, on-off-dash-seq) ]
722
720
"""
723
- if is_string_like (ls ):
724
- dashes = GraphicsContextBase .dashd [ls ]
725
- elif iterable (ls ) and len (ls )== 2 :
721
+ if cbook . is_string_like (ls ):
722
+ dashes = backend_bases . GraphicsContextBase .dashd [ls ]
723
+ elif cbook . iterable (ls ) and len (ls )== 2 :
726
724
dashes = ls
727
725
else : raise ValueError ('Do not know how to convert %s to dashes' % ls )
728
726
@@ -738,7 +736,7 @@ def set_color(self, c):
738
736
739
737
ACCEPTS: matplotlib color arg or sequence of rgba tuples
740
738
"""
741
- self ._colors = colorConverter .to_rgba_list (c )
739
+ self ._colors = _colors . colorConverter .to_rgba_list (c )
742
740
743
741
def color (self , c ):
744
742
"""
@@ -764,7 +762,7 @@ def set_alpha(self, alpha):
764
762
try : float (alpha )
765
763
except TypeError : raise TypeError ('alpha must be a float' )
766
764
else :
767
- Artist .set_alpha (self , alpha )
765
+ artist . Artist .set_alpha (self , alpha )
768
766
self ._colors = [(r ,g ,b ,alpha ) for r ,g ,b ,a in self ._colors ]
769
767
770
768
def get_linewidth (self ):
0 commit comments