4949
5050MaskedArray = ma .MaskedArray
5151
52+
5253class TransformNode (object ):
5354 """
5455 :class:`TransformNode` is the base class for anything that
@@ -63,13 +64,13 @@ class TransformNode(object):
6364 # invalidation was "affine-only", the _invalid member is set to
6465 # INVALID_AFFINE_ONLY
6566 INVALID_NON_AFFINE = 1
66- INVALID_AFFINE = 2
67- INVALID = INVALID_NON_AFFINE | INVALID_AFFINE
67+ INVALID_AFFINE = 2
68+ INVALID = INVALID_NON_AFFINE | INVALID_AFFINE
6869
6970 # Some metadata about the transform, used to determine whether an
7071 # invalidation is affine-only
7172 is_affine = False
72- is_bbox = False
73+ is_bbox = False
7374
7475 pass_through = False
7576 """
@@ -150,7 +151,8 @@ def _invalidate_internal(self, value, invalidating_node):
150151 self ._invalid = value
151152
152153 for parent in self ._parents .itervalues ():
153- parent ._invalidate_internal (value = value , invalidating_node = self )
154+ parent ._invalidate_internal (value = value ,
155+ invalidating_node = self )
154156
155157 def set_children (self , * children ):
156158 """
@@ -164,6 +166,7 @@ def set_children(self, *children):
164166
165167 if DEBUG :
166168 _set_children = set_children
169+
167170 def set_children (self , * children ):
168171 self ._set_children (* children )
169172 self ._children = children
@@ -212,7 +215,9 @@ def recurse(root):
212215 props ['style' ] = 'bold'
213216 props ['shape' ] = 'box'
214217 props ['label' ] = '"%s"' % label
215- props = ' ' .join (['%s=%s' % (key , val ) for key , val in props .iteritems ()])
218+ props = ' ' .join (['%s=%s' % (key , val )
219+ for key , val
220+ in props .iteritems ()])
216221
217222 fobj .write ('%s [%s];\n ' %
218223 (hash (root ), props ))
@@ -224,10 +229,10 @@ def recurse(root):
224229 if val is child :
225230 name = key
226231 break
227- fobj .write ('"%s" -> "%s" [label="%s", fontsize=10];\n ' % (
228- hash (root ),
229- hash (child ),
230- name ))
232+ fobj .write ('"%s" -> "%s" [label="%s", fontsize=10];\n '
233+ % ( hash (root ),
234+ hash (child ),
235+ name ))
231236 recurse (child )
232237
233238 fobj .write ("digraph G {\n " )
@@ -259,8 +264,8 @@ def _check(points):
259264 if ma .isMaskedArray (points ):
260265 warnings .warn ("Bbox bounds are a masked array." )
261266 points = np .asarray (points )
262- if (points [1 ,0 ] - points [0 ,0 ] == 0 or
263- points [1 ,1 ] - points [0 ,1 ] == 0 ):
267+ if (points [1 , 0 ] - points [0 , 0 ] == 0 or
268+ points [1 , 1 ] - points [0 , 1 ] == 0 ):
264269 warnings .warn ("Singular Bbox." )
265270 _check = staticmethod (_check )
266271
@@ -295,30 +300,30 @@ def _get_y0(self):
295300 def _get_x1 (self ):
296301 return self .get_points ()[1 , 0 ]
297302 x1 = property (_get_x1 , None , None , """
298- (property) :attr:`x1` is the second of the pair of *x* coordinates that
299- define the bounding box. :attr:`x1` is not guaranteed to be
303+ (property) :attr:`x1` is the second of the pair of *x* coordinates
304+ that define the bounding box. :attr:`x1` is not guaranteed to be
300305 greater than :attr:`x0`. If you require that, use :attr:`xmax`.""" )
301306
302307 def _get_y1 (self ):
303308 return self .get_points ()[1 , 1 ]
304309 y1 = property (_get_y1 , None , None , """
305- (property) :attr:`y1` is the second of the pair of *y* coordinates that
306- define the bounding box. :attr:`y1` is not guaranteed to be
310+ (property) :attr:`y1` is the second of the pair of *y* coordinates
311+ that define the bounding box. :attr:`y1` is not guaranteed to be
307312 greater than :attr:`y0`. If you require that, use :attr:`ymax`.""" )
308313
309314 def _get_p0 (self ):
310315 return self .get_points ()[0 ]
311316 p0 = property (_get_p0 , None , None , """
312- (property) :attr:`p0` is the first pair of (*x*, *y*) coordinates that
313- define the bounding box. It is not guaranteed to be the bottom-left
314- corner. For that, use :attr:`min`.""" )
317+ (property) :attr:`p0` is the first pair of (*x*, *y*) coordinates
318+ that define the bounding box. It is not guaranteed to be the
319+ bottom-left corner. For that, use :attr:`min`.""" )
315320
316321 def _get_p1 (self ):
317322 return self .get_points ()[1 ]
318323 p1 = property (_get_p1 , None , None , """
319- (property) :attr:`p1` is the second pair of (*x*, *y*) coordinates that
320- define the bounding box. It is not guaranteed to be the top-right
321- corner. For that, use :attr:`max`.""" )
324+ (property) :attr:`p1` is the second pair of (*x*, *y*) coordinates
325+ that define the bounding box. It is not guaranteed to be the
326+ top-right corner. For that, use :attr:`max`.""" )
322327
323328 def _get_xmin (self ):
324329 return min (self .get_points ()[:, 0 ])
@@ -398,7 +403,8 @@ def _get_bounds(self):
398403 def _get_extents (self ):
399404 return self .get_points ().flatten ().copy ()
400405 extents = property (_get_extents , None , None , """
401- (property) Returns (:attr:`x0`, :attr:`y0`, :attr:`x1`, :attr:`y1`).""" )
406+ (property) Returns (:attr:`x0`, :attr:`y0`, :attr:`x1`,
407+ :attr:`y1`).""" )
402408
403409 def get_points (self ):
404410 return NotImplementedError ()
@@ -468,6 +474,7 @@ def fully_containsy(self, y):
468474 :attr:`y1`.
469475 """
470476 y0 , y1 = self .intervaly
477+ # FIXME x is not define. This method probably doesn't work.
471478 return ((y0 < y1
472479 and (x > y0 and x < y1 ))
473480 or (x > y1 and x < y0 ))
@@ -517,15 +524,16 @@ def inverse_transformed(self, transform):
517524 return Bbox (transform .inverted ().transform (self .get_points ()))
518525
519526 coefs = {'C' : (0.5 , 0.5 ),
520- 'SW' : (0 ,0 ),
527+ 'SW' : (0 , 0 ),
521528 'S' : (0.5 , 0 ),
522529 'SE' : (1.0 , 0 ),
523530 'E' : (1.0 , 0.5 ),
524531 'NE' : (1.0 , 1.0 ),
525532 'N' : (0.5 , 1.0 ),
526533 'NW' : (0 , 1.0 ),
527534 'W' : (0 , 0.5 )}
528- def anchored (self , c , container = None ):
535+
536+ def anchored (self , c , container = None ):
529537 """
530538 Return a copy of the :class:`Bbox`, shifted to position *c*
531539 within a container.
@@ -555,8 +563,8 @@ def anchored(self, c, container = None):
555563 cx , cy = c
556564 L , B , W , H = self .bounds
557565 return Bbox (self ._points +
558- [(l + cx * (w - W )) - L ,
559- (b + cy * (h - H )) - B ])
566+ [(l + cx * (w - W )) - L ,
567+ (b + cy * (h - H )) - B ])
560568
561569 def shrunk (self , mx , my ):
562570 """
@@ -569,7 +577,7 @@ def shrunk(self, mx, my):
569577 return Bbox ([self ._points [0 ],
570578 self ._points [0 ] + [mx * w , my * h ]])
571579
572- def shrunk_to_aspect (self , box_aspect , container = None , fig_aspect = 1.0 ):
580+ def shrunk_to_aspect (self , box_aspect , container = None , fig_aspect = 1.0 ):
573581 """
574582 Return a copy of the :class:`Bbox`, shrunk so that it is as
575583 large as it can be while having the desired aspect ratio,
@@ -583,11 +591,11 @@ def shrunk_to_aspect(self, box_aspect, container = None, fig_aspect = 1.0):
583591 if container is None :
584592 container = self
585593 w , h = container .size
586- H = w * box_aspect / fig_aspect
594+ H = w * box_aspect / fig_aspect
587595 if H <= h :
588596 W = w
589597 else :
590- W = h * fig_aspect / box_aspect
598+ W = h * fig_aspect / box_aspect
591599 H = h
592600 return Bbox ([self ._points [0 ],
593601 self ._points [0 ] + (W , H )])
@@ -749,6 +757,7 @@ def __init__(self, points, **kwargs):
749757 self ._points_orig = self ._points .copy ()
750758 if DEBUG :
751759 ___init__ = __init__
760+
752761 def __init__ (self , points , ** kwargs ):
753762 self ._check (points )
754763 self .___init__ (points , ** kwargs )
@@ -758,6 +767,7 @@ def invalidate(self):
758767 TransformNode .invalidate (self )
759768
760769 _unit_values = np .array ([[0.0 , 0.0 ], [1.0 , 1.0 ]], np .float_ )
770+
761771 @staticmethod
762772 def unit ():
763773 """
@@ -822,7 +832,9 @@ def update_from_data(self, x, y, ignore=None):
822832 - when None, use the last value passed to :meth:`ignore`.
823833 """
824834 warnings .warn (
825- "update_from_data requires a memory copy -- please replace with update_from_data_xy" )
835+ "update_from_data requires a memory copy -- please replace with "
836+ "update_from_data_xy" )
837+
826838 xy = np .hstack ((x .reshape ((len (x ), 1 )), y .reshape ((len (y ), 1 ))))
827839 return self .update_from_data_xy (xy , ignore )
828840
@@ -856,13 +868,12 @@ def update_from_path(self, path, ignore=None, updatex=True, updatey=True):
856868 if changed :
857869 self .invalidate ()
858870 if updatex :
859- self ._points [:,0 ] = points [:,0 ]
871+ self ._points [:, 0 ] = points [:, 0 ]
860872 self ._minpos [0 ] = minpos [0 ]
861873 if updatey :
862- self ._points [:,1 ] = points [:,1 ]
874+ self ._points [:, 1 ] = points [:, 1 ]
863875 self ._minpos [1 ] = minpos [1 ]
864876
865-
866877 def update_from_data_xy (self , xy , ignore = None , updatex = True , updatey = True ):
867878 """
868879 Update the bounds of the :class:`Bbox` based on the passed in
@@ -929,7 +940,7 @@ def _set_intervaly(self, interval):
929940
930941 def _set_bounds (self , bounds ):
931942 l , b , w , h = bounds
932- points = np .array ([[l , b ], [l + w , b + h ]], np .float_ )
943+ points = np .array ([[l , b ], [l + w , b + h ]], np .float_ )
933944 if np .any (self ._points != points ):
934945 self ._points = points
935946 self .invalidate ()
@@ -980,12 +991,13 @@ def mutated(self):
980991
981992 def mutatedx (self ):
982993 'return whether the x-limits have changed since init'
983- return (self ._points [0 ,0 ]!= self ._points_orig [0 ,0 ] or
984- self ._points [1 ,0 ]!= self ._points_orig [1 ,0 ])
994+ return (self ._points [0 , 0 ] != self ._points_orig [0 , 0 ] or
995+ self ._points [1 , 0 ] != self ._points_orig [1 , 0 ])
996+
985997 def mutatedy (self ):
986998 'return whether the y-limits have changed since init'
987- return (self ._points [0 ,1 ] != self ._points_orig [0 ,1 ] or
988- self ._points [1 ,1 ] != self ._points_orig [1 ,1 ])
999+ return (self ._points [0 , 1 ] != self ._points_orig [0 , 1 ] or
1000+ self ._points [1 , 1 ] != self ._points_orig [1 , 1 ])
9891001
9901002
9911003class TransformedBbox (BboxBase ):
@@ -1025,6 +1037,7 @@ def get_points(self):
10251037
10261038 if DEBUG :
10271039 _get_points = get_points
1040+
10281041 def get_points (self ):
10291042 points = self ._get_points ()
10301043 self ._check (points )
@@ -1161,24 +1174,27 @@ def contains_branch_seperately(self, other_transform):
11611174 if self .output_dims != 2 :
11621175 raise ValueError ('contains_branch_seperately only supports '
11631176 'transforms with 2 output dimensions' )
1164- # for a non-blended transform each seperate dimension is the same, so just
1165- # return the appropriate shape.
1177+ # for a non-blended transform each seperate dimension is the same, so
1178+ # just return the appropriate shape.
11661179 return [self .contains_branch (other_transform )] * 2
11671180
11681181 def __sub__ (self , other ):
11691182 """
11701183 Returns a transform stack which goes all the way down self's transform
1171- stack, and then ascends back up other's stack. If it can, this is optimised::
1184+ stack, and then ascends back up other's stack. If it can, this is
1185+ optimised::
11721186
11731187 # normally
11741188 A - B == a + b.inverted()
11751189
1176- # sometimes, when A contains the tree B there is no need to descend all the way down
1177- # to the base of A (via B), instead we can just stop at B.
1190+ # sometimes, when A contains the tree B there is no need to
1191+ # descend all the way down to the base of A (via B), instead we
1192+ # can just stop at B.
11781193
11791194 (A + B) - (B)^-1 == A
11801195
1181- # similarly, when B contains tree A, we can avoid decending A at all, basically:
1196+ # similarly, when B contains tree A, we can avoid decending A at
1197+ # all, basically:
11821198 A - (A + B) == ((B + A) - A).inverted() or B^-1
11831199
11841200 For clarity, the result of ``(A + B) - B + B == (A + B)``.
@@ -1358,15 +1374,15 @@ def transform_angles(self, angles, pts, radians=False, pushoff=1e-5):
13581374 angles = angles / 180.0 * np .pi
13591375
13601376 # Move a short distance away
1361- pts2 = pts + pushoff * np .c_ [ np .cos (angles ), np .sin (angles ) ]
1377+ pts2 = pts + pushoff * np .c_ [np .cos (angles ), np .sin (angles )]
13621378
13631379 # Transform both sets of points
1364- tpts = self .transform ( pts )
1365- tpts2 = self .transform ( pts2 )
1380+ tpts = self .transform (pts )
1381+ tpts2 = self .transform (pts2 )
13661382
13671383 # Calculate transformed angles
13681384 d = tpts2 - tpts
1369- a = np .arctan2 ( d [:,1 ], d [:,0 ] )
1385+ a = np .arctan2 (d [:, 1 ], d [:, 0 ] )
13701386
13711387 # Convert back to degrees if desired
13721388 if not radians :
@@ -1419,6 +1435,7 @@ def __eq__(self, other):
14191435 return self ._child .__eq__ (other )
14201436
14211437 if DEBUG :
1438+
14221439 def __str__ (self ):
14231440 return str (self ._child )
14241441
@@ -1441,15 +1458,15 @@ def _set(self, child):
14411458 self ._child = child
14421459 self .set_children (child )
14431460
1444- self .transform = child .transform
1445- self .transform_affine = child .transform_affine
1446- self .transform_non_affine = child .transform_non_affine
1447- self .transform_path = child .transform_path
1448- self .transform_path_affine = child .transform_path_affine
1461+ self .transform = child .transform
1462+ self .transform_affine = child .transform_affine
1463+ self .transform_non_affine = child .transform_non_affine
1464+ self .transform_path = child .transform_path
1465+ self .transform_path_affine = child .transform_path_affine
14491466 self .transform_path_non_affine = child .transform_path_non_affine
1450- self .get_affine = child .get_affine
1451- self .inverted = child .inverted
1452- self .get_matrix = child .get_matrix
1467+ self .get_affine = child .get_affine
1468+ self .inverted = child .inverted
1469+ self .get_matrix = child .get_matrix
14531470
14541471 # note we do not wrap other properties here since the transform's
14551472 # child can be changed with WrappedTransform.set and so checking
@@ -1517,7 +1534,8 @@ def transform(self, values):
15171534 transform .__doc__ = Transform .transform .__doc__
15181535
15191536 def transform_affine (self , values ):
1520- raise NotImplementedError ('Affine subclasses should override this method.' )
1537+ raise NotImplementedError ('Affine subclasses should override this '
1538+ 'method.' )
15211539 transform_affine .__doc__ = Transform .transform_affine .__doc__
15221540
15231541 def transform_non_affine (self , points ):
@@ -1605,6 +1623,7 @@ def transform_point(self, point):
16051623
16061624 if DEBUG :
16071625 _transform_affine = transform_affine
1626+
16081627 def transform_affine (self , points ):
16091628 # The major speed trap here is just converting to the
16101629 # points to an array in the first place. If we can use
@@ -1678,7 +1697,7 @@ def from_values(a, b, c, d, e, f):
16781697 """
16791698 return Affine2D (
16801699 np .array ([a , c , e , b , d , f , 0.0 , 0.0 , 1.0 ], np .float_ )
1681- .reshape ((3 ,3 )))
1700+ .reshape ((3 , 3 )))
16821701
16831702 def get_matrix (self ):
16841703 """
@@ -1759,7 +1778,7 @@ def rotate_deg(self, degrees):
17591778 calls to :meth:`rotate`, :meth:`rotate_deg`, :meth:`translate`
17601779 and :meth:`scale`.
17611780 """
1762- return self .rotate (degrees * np .pi / 180. )
1781+ return self .rotate (degrees * np .pi / 180. )
17631782
17641783 def rotate_around (self , x , y , theta ):
17651784 """
0 commit comments