11from __future__ import division
22import math
3- from matplotlib import rcParams
4- from numerix import array , arange , sin , cos , pi , Float , sqrt , \
5- matrixmultiply , sqrt , nonzero , equal , asarray , dot , concatenate
6- from artist import Artist , setp , kwdocd
7- from cbook import enumerate , dedent
8- from colors import colorConverter
9- from lines import Line2D
10- from transforms import bound_vertices
11- import matplotlib .nxutils as nxutils
12-
13- from numerix .mlab import amin
14- from mlab import dist_point_to_segment
15-
16- import artist
173
4+ import matplotlib as mpl
5+ import numpy as npy
6+ import matplotlib .cbook as cbook
7+ import matplotlib .artist as artist
8+ import matplotlib .colors as colors
9+ import matplotlib .lines as lines
10+ import matplotlib .transforms as transforms
11+ import matplotlib .nxutils as nxutils
12+ import matplotlib .mlab as mlab
13+ import matplotlib .artist as artist
1814
1915
2016# these are not available for the object inspector until after the
2117# class is build so we define an initial set here for the init
2218# function and they will be overridden after object defn
23- kwdocd ['Patch' ] = """\
19+ artist . kwdocd ['Patch' ] = """\
2420 alpha: float
2521 animated: [True | False]
2622 antialiased or aa: [True | False]
3935 zorder: any number
4036 """
4137
42- class Patch (Artist ):
38+ class Patch (artist . Artist ):
4339 """
4440 A patch is a 2D thingy with a face color and an edge color
4541
@@ -61,12 +57,12 @@ def __init__(self,
6157 The following kwarg properties are supported
6258 %(Patch)s
6359 """
64- Artist .__init__ (self )
60+ artist . Artist .__init__ (self )
6561
66- if edgecolor is None : edgecolor = rcParams ['patch.edgecolor' ]
67- if facecolor is None : facecolor = rcParams ['patch.facecolor' ]
68- if linewidth is None : linewidth = rcParams ['patch.linewidth' ]
69- if antialiased is None : antialiased = rcParams ['patch.antialiased' ]
62+ if edgecolor is None : edgecolor = mpl . rcParams ['patch.edgecolor' ]
63+ if facecolor is None : facecolor = mpl . rcParams ['patch.facecolor' ]
64+ if linewidth is None : linewidth = mpl . rcParams ['patch.linewidth' ]
65+ if antialiased is None : antialiased = mpl . rcParams ['patch.antialiased' ]
7066
7167 self ._edgecolor = edgecolor
7268 self ._facecolor = facecolor
@@ -75,8 +71,8 @@ def __init__(self,
7571 self ._hatch = hatch
7672 self .fill = fill
7773
78- if len (kwargs ): setp (self , ** kwargs )
79- __init__ .__doc__ = dedent (__init__ .__doc__ ) % kwdocd
74+ if len (kwargs ): artist . setp (self , ** kwargs )
75+ __init__ .__doc__ = cbook . dedent (__init__ .__doc__ ) % artist . kwdocd
8076
8177 def pick (self , mouseevent ):
8278 """
@@ -98,7 +94,7 @@ def pick(self, mouseevent):
9894
9995
10096 def update_from (self , other ):
101- Artist .update_from (self , other )
97+ artist . Artist .update_from (self , other )
10298 self .set_edgecolor (other .get_edgecolor ())
10399 self .set_facecolor (other .get_facecolor ())
104100 self .set_fill (other .get_fill ())
@@ -206,7 +202,7 @@ def draw(self, renderer):
206202 gc .set_capstyle ('projecting' )
207203
208204 if not self .fill or self ._facecolor is None : rgbFace = None
209- else : rgbFace = colorConverter .to_rgb (self ._facecolor )
205+ else : rgbFace = colors . colorConverter .to_rgb (self ._facecolor )
210206
211207 if self ._hatch :
212208 gc .set_hatch (self ._hatch )
@@ -229,7 +225,7 @@ def get_verts(self):
229225 def get_window_extent (self , renderer = None ):
230226 verts = self .get_verts ()
231227 tverts = self .get_transform ().seq_xy_tups (verts )
232- return bound_vertices (tverts )
228+ return transforms . bound_vertices (tverts )
233229
234230
235231
@@ -283,15 +279,15 @@ def __init__(self, patch, ox, oy, props=None, **kwargs):
283279 self .patch = patch
284280 self .props = props
285281 self ._update ()
286- __init__ .__doc__ = dedent (__init__ .__doc__ ) % kwdocd
282+ __init__ .__doc__ = cbook . dedent (__init__ .__doc__ ) % artist . kwdocd
287283
288284
289285 def _update (self ):
290286 self .update_from (self .patch )
291287 if self .props is not None :
292288 self .update (self .props )
293289 else :
294- r ,g ,b ,a = colorConverter .to_rgba (self .patch .get_facecolor ())
290+ r ,g ,b ,a = colors . colorConverter .to_rgba (self .patch .get_facecolor ())
295291 rho = 0.3
296292 r = rho * r
297293 g = rho * g
@@ -335,7 +331,7 @@ def __init__(self, xy, width, height,
335331
336332 self .xy = list (xy )
337333 self .width , self .height = width , height
338- __init__ .__doc__ = dedent (__init__ .__doc__ ) % kwdocd
334+ __init__ .__doc__ = cbook . dedent (__init__ .__doc__ ) % artist . kwdocd
339335
340336
341337 def get_verts (self ):
@@ -436,18 +432,18 @@ def __init__(self, xy, numVertices, radius=5, orientation=0,
436432 self .radius = radius
437433 self .orientation = orientation
438434
439- __init__ .__doc__ = dedent (__init__ .__doc__ ) % kwdocd
435+ __init__ .__doc__ = cbook . dedent (__init__ .__doc__ ) % artist . kwdocd
440436
441437
442438
443439 def get_verts (self ):
444- theta = 2 * pi / self .numVertices * arange (self .numVertices ) + \
440+ theta = 2 * npy . pi / self .numVertices * npy . arange (self .numVertices ) + \
445441 self .orientation
446442 r = float (self .radius )
447443 x , y = map (float , self .xy )
448444
449- xs = x + r * cos (theta )
450- ys = y + r * sin (theta )
445+ xs = x + r * npy . cos (theta )
446+ ys = y + r * npy . sin (theta )
451447
452448 #xs = self.convert_xunits(xs)
453449 #ys = self.convert_yunits(ys)
@@ -474,7 +470,7 @@ def __init__(self, xy, **kwargs):
474470 if not isinstance (xy , list ):
475471 xy = list (xy )
476472 self .xy = xy
477- __init__ .__doc__ = dedent (__init__ .__doc__ ) % kwdocd
473+ __init__ .__doc__ = cbook . dedent (__init__ .__doc__ ) % artist . kwdocd
478474
479475
480476
@@ -499,14 +495,14 @@ def __init__(self, center, r, theta1, theta2,
499495
500496 """
501497 xc , yc = center
502- rads = (math .pi / 180. )* arange (theta1 , theta2 + 0.1 * dtheta , dtheta )
503- xs = r * cos (rads )+ xc
504- ys = r * sin (rads )+ yc
498+ rads = (math .pi / 180. )* npy . arange (theta1 , theta2 + 0.1 * dtheta , dtheta )
499+ xs = r * npy . cos (rads )+ xc
500+ ys = r * npy . sin (rads )+ yc
505501 verts = [center ]
506502 verts .extend ([(x ,y ) for x ,y in zip (xs ,ys )])
507503
508504 Polygon .__init__ (self , verts , ** kwargs )
509- __init__ .__doc__ = dedent (__init__ .__doc__ ) % kwdocd
505+ __init__ .__doc__ = cbook . dedent (__init__ .__doc__ ) % artist . kwdocd
510506
511507class Arrow (Polygon ):
512508 """
@@ -519,20 +515,20 @@ def __init__( self, x, y, dx, dy, width=1.0, **kwargs ):
519515 Valid kwargs are:
520516 %(Patch)s
521517 """
522- arrow = array ( [
518+ arrow = npy . array ( [
523519 [ 0.0 , 0.1 ], [ 0.0 , - 0.1 ],
524520 [ 0.8 , - 0.1 ], [ 0.8 , - 0.3 ],
525521 [ 1.0 , 0.0 ], [ 0.8 , 0.3 ],
526522 [ 0.8 , 0.1 ] ] )
527- L = sqrt (dx ** 2 + dy ** 2 ) or 1 # account for div by zero
523+ L = npy . sqrt (dx ** 2 + dy ** 2 ) or 1 # account for div by zero
528524 arrow [:,0 ] *= L
529525 arrow [:,1 ] *= width
530526 cx = float (dx )/ L
531527 sx = float (dy )/ L
532- M = array ( [ [ cx , sx ],[ - sx , cx ] ] )
533- verts = matrixmultiply ( arrow , M )+ [x ,y ]
528+ M = npy . array ( [ [ cx , sx ],[ - sx , cx ] ] )
529+ verts = npy . matrixmultiply ( arrow , M )+ [x ,y ]
534530 Polygon .__init__ ( self , [ tuple (t ) for t in verts ], ** kwargs )
535- __init__ .__doc__ = dedent (__init__ .__doc__ ) % kwdocd
531+ __init__ .__doc__ = cbook . dedent (__init__ .__doc__ ) % artist . kwdocd
536532
537533class FancyArrow (Polygon ):
538534 """Like Arrow, but lets you set head width and head height independently."""
@@ -561,7 +557,7 @@ def __init__(self, x, y, dx, dy, width=0.001, length_includes_head=False, \
561557 if head_length is None :
562558 head_length = 1.5 * head_width
563559
564- distance = sqrt (dx ** 2 + dy ** 2 )
560+ distance = npy . sqrt (dx ** 2 + dy ** 2 )
565561 if length_includes_head :
566562 length = distance
567563 else :
@@ -571,7 +567,7 @@ def __init__(self, x, y, dx, dy, width=0.001, length_includes_head=False, \
571567 else :
572568 #start by drawing horizontal arrow, point at (0,0)
573569 hw , hl , hs , lw = head_width , head_length , overhang , width
574- left_half_arrow = array ([
570+ left_half_arrow = npy . array ([
575571 [0.0 ,0.0 ], #tip
576572 [- hl , - hw / 2.0 ], #leftmost
577573 [- hl * (1 - hs ), - lw / 2.0 ], #meets stem
@@ -592,16 +588,16 @@ def __init__(self, x, y, dx, dy, width=0.001, length_includes_head=False, \
592588 if shape == 'right' :
593589 coords = right_half_arrow
594590 elif shape == 'full' :
595- coords = concatenate ([left_half_arrow ,right_half_arrow [::- 1 ]])
591+ coords = npy . concatenate ([left_half_arrow ,right_half_arrow [::- 1 ]])
596592 else :
597593 raise ValueError , "Got unknown shape: %s" % shape
598594 cx = float (dx )/ distance
599595 sx = float (dy )/ distance
600- M = array ([[cx , sx ],[- sx ,cx ]])
601- verts = matrixmultiply (coords , M ) + (x + dx , y + dy )
596+ M = npy . array ([[cx , sx ],[- sx ,cx ]])
597+ verts = npy . matrixmultiply (coords , M ) + (x + dx , y + dy )
602598
603599 Polygon .__init__ (self , map (tuple , verts ), ** kwargs )
604- __init__ .__doc__ = dedent (__init__ .__doc__ ) % kwdocd
600+ __init__ .__doc__ = cbook . dedent (__init__ .__doc__ ) % artist . kwdocd
605601
606602class YAArrow (Polygon ):
607603 """
@@ -631,7 +627,7 @@ def __init__(self, dpi, xytip, xybase, width=4, frac=0.1, headwidth=12, **kwargs
631627 self .headwidth = headwidth
632628 verts = self .get_verts ()
633629 Polygon .__init__ (self , verts , ** kwargs )
634- __init__ .__doc__ = dedent (__init__ .__doc__ ) % kwdocd
630+ __init__ .__doc__ = cbook . dedent (__init__ .__doc__ ) % artist . kwdocd
635631
636632
637633
@@ -699,7 +695,7 @@ def __init__(self, xy, radius=5,
699695 radius ,
700696 orientation = 0 ,
701697 ** kwargs )
702- __init__ .__doc__ = dedent (__init__ .__doc__ ) % kwdocd
698+ __init__ .__doc__ = cbook . dedent (__init__ .__doc__ ) % artist . kwdocd
703699
704700
705701class Ellipse (Patch ):
@@ -718,7 +714,7 @@ def __init__(self, xy, width, height, angle=0.0, **kwargs):
718714 """
719715 Patch .__init__ (self , ** kwargs )
720716
721- # self.center = array(xy, Float )
717+ # self.center = npy. array(xy, npy.float )
722718 self .center = xy
723719 self .width , self .height = width , height
724720 self .angle = angle
@@ -729,7 +725,7 @@ def get_verts(self):
729725 b ,t = y - self .height / 2.0 , y + self .height / 2.0
730726 x ,l ,r = self .convert_xunits ((x ,l ,r ))
731727 y ,b ,t = self .convert_yunits ((y ,b ,t ))
732- return array (((x ,y ),(l ,y ),(x ,t ),(r ,y ),(x ,b )), Float )
728+ return npy . array (((x ,y ),(l ,y ),(x ,t ),(r ,y ),(x ,b )), npy . float )
733729
734730 def draw (self , renderer ):
735731 if not self .get_visible (): return
@@ -744,7 +740,7 @@ def draw(self, renderer):
744740 gc .set_capstyle ('projecting' )
745741
746742 if not self .fill or self ._facecolor is None : rgbFace = None
747- else : rgbFace = colorConverter .to_rgb (self ._facecolor )
743+ else : rgbFace = colors . colorConverter .to_rgb (self ._facecolor )
748744
749745 if self ._hatch :
750746 gc .set_hatch (self ._hatch )
@@ -779,7 +775,7 @@ def __init__(self, xy, radius=5,
779775
780776 self .radius = radius
781777 Ellipse .__init__ (self , xy , radius * 2 , radius * 2 , ** kwargs )
782- __init__ .__doc__ = dedent (__init__ .__doc__ ) % kwdocd
778+ __init__ .__doc__ = cbook . dedent (__init__ .__doc__ ) % artist . kwdocd
783779
784780
785781class PolygonInteractor :
@@ -808,7 +804,7 @@ def __init__(self, poly):
808804 self .poly = poly
809805 self .poly .verts = list (self .poly .verts )
810806 x , y = zip (* self .poly .verts )
811- self .line = Line2D (x ,y ,marker = 'o' , markerfacecolor = 'r' )
807+ self .line = lines . Line2D (x ,y ,marker = 'o' , markerfacecolor = 'r' )
812808 #self._update_line(poly)
813809
814810 cid = self .poly .add_callback (self .poly_changed )
@@ -825,7 +821,7 @@ def poly_changed(self, poly):
825821 'this method is called whenever the polygon object is called'
826822 # only copy the artist props to the line (except visibility)
827823 vis = self .line .get_visible ()
828- Artist .update_from (self .line , poly )
824+ artist . Artist .update_from (self .line , poly )
829825 self .line .set_visible (vis ) # don't use the poly visibility state
830826
831827
@@ -835,8 +831,8 @@ def get_ind_under_point(self, event):
835831
836832 # display coords
837833 xt , yt = self .poly .get_transform ().numerix_x_y (x , y )
838- d = sqrt ((xt - event .x )** 2 + (yt - event .y )** 2 )
839- indseq = nonzero (equal (d , amin (d )))
834+ d = npy . sqrt ((xt - event .x )** 2 + (yt - event .y )** 2 )
835+ indseq = npy . nonzero (npy . equal (d , npy . amin (d )))
840836 ind = indseq [0 ]
841837
842838 if d [ind ]>= self .epsilon :
@@ -875,7 +871,7 @@ def key_press_callback(self, event):
875871 for i in range (len (xys )- 1 ):
876872 s0 = xys [i ]
877873 s1 = xys [i + 1 ]
878- d = dist_point_to_segment (p , s0 , s1 )
874+ d = mlab . dist_point_to_segment (p , s0 , s1 )
879875 if d <= self .epsilon :
880876 self .poly .verts .insert (i + 1 , (event .xdata , event .ydata ))
881877 self .line .set_data (zip (* self .poly .verts ))
0 commit comments