@@ -1461,17 +1461,52 @@ def add_line(self, line):
14611461
14621462 self ._update_line_limits (line )
14631463 if not line .get_label ():
1464- line .set_label ('_line%d' % len (self .lines ))
1464+ line .set_label ('_line%d' % len (self .lines ))
14651465 self .lines .append (line )
14661466 line ._remove_method = lambda h : self .lines .remove (h )
14671467 return line
14681468
14691469 def _update_line_limits (self , line ):
1470- p = line .get_path ()
1471- if p .vertices .size > 0 :
1472- self .dataLim .update_from_path (p , self .ignore_existing_data_limits ,
1473- updatex = line .x_isdata ,
1474- updatey = line .y_isdata )
1470+ """Figures out the data limit of the given line, updating self.dataLim."""
1471+ path = line .get_path ()
1472+ if path .vertices .size == 0 :
1473+ return
1474+
1475+ line_trans = line .get_transform ()
1476+
1477+ if line_trans == self .transData :
1478+ data_path = path
1479+
1480+ elif any (line_trans .contains_branch_seperately (self .transData )):
1481+ # identify the transform to go from line's coordinates
1482+ # to data coordinates
1483+ trans_to_data = line_trans - self .transData
1484+
1485+ # if transData is affine we can use the cached non-affine component
1486+ # of line's path. (since the non-affine part of line_trans is
1487+ # entirely encapsulated in trans_to_data).
1488+ if self .transData .is_affine :
1489+ line_trans_path = line ._get_transformed_path ()
1490+ na_path , _ = line_trans_path .get_transformed_path_and_affine ()
1491+ data_path = trans_to_data .transform_path_affine (na_path )
1492+ else :
1493+ data_path = trans_to_data .transform_path (path )
1494+ else :
1495+ # for backwards compatibility we update the dataLim with the
1496+ # coordinate range of the given path, even though the coordinate
1497+ # systems are completely different. This may occur in situations
1498+ # such as when ax.transAxes is passed through for absolute
1499+ # positioning.
1500+ data_path = path
1501+
1502+ if data_path .vertices .size > 0 :
1503+ updatex , updatey = line_trans .contains_branch_seperately (
1504+ self .transData
1505+ )
1506+ self .dataLim .update_from_path (data_path ,
1507+ self .ignore_existing_data_limits ,
1508+ updatex = updatex ,
1509+ updatey = updatey )
14751510 self .ignore_existing_data_limits = False
14761511
14771512 def add_patch (self , p ):
@@ -1507,11 +1542,14 @@ def _update_patch_limits(self, patch):
15071542 if vertices .size > 0 :
15081543 xys = patch .get_patch_transform ().transform (vertices )
15091544 if patch .get_data_transform () != self .transData :
1510- transform = (patch .get_data_transform () +
1511- self .transData .inverted ())
1512- xys = transform .transform (xys )
1513- self .update_datalim (xys , updatex = patch .x_isdata ,
1514- updatey = patch .y_isdata )
1545+ patch_to_data = (patch .get_data_transform () -
1546+ self .transData )
1547+ xys = patch_to_data .transform (xys )
1548+
1549+ updatex , updatey = patch .get_transform ().\
1550+ contains_branch_seperately (self .transData )
1551+ self .update_datalim (xys , updatex = updatex ,
1552+ updatey = updatey )
15151553
15161554
15171555 def add_table (self , tab ):
@@ -1599,13 +1637,13 @@ def _process_unit_info(self, xdata=None, ydata=None, kwargs=None):
15991637 if xdata is not None :
16001638 # we only need to update if there is nothing set yet.
16011639 if not self .xaxis .have_units ():
1602- self .xaxis .update_units (xdata )
1640+ self .xaxis .update_units (xdata )
16031641 #print '\tset from xdata', self.xaxis.units
16041642
16051643 if ydata is not None :
16061644 # we only need to update if there is nothing set yet.
16071645 if not self .yaxis .have_units ():
1608- self .yaxis .update_units (ydata )
1646+ self .yaxis .update_units (ydata )
16091647 #print '\tset from ydata', self.yaxis.units
16101648
16111649 # process kwargs 2nd since these will override default units
@@ -3424,7 +3462,6 @@ def axhline(self, y=0, xmin=0, xmax=1, **kwargs):
34243462 trans = mtransforms .blended_transform_factory (
34253463 self .transAxes , self .transData )
34263464 l = mlines .Line2D ([xmin ,xmax ], [y ,y ], transform = trans , ** kwargs )
3427- l .x_isdata = False
34283465 self .add_line (l )
34293466 self .autoscale_view (scalex = False , scaley = scaley )
34303467 return l
@@ -3489,7 +3526,6 @@ def axvline(self, x=0, ymin=0, ymax=1, **kwargs):
34893526 trans = mtransforms .blended_transform_factory (
34903527 self .transData , self .transAxes )
34913528 l = mlines .Line2D ([x ,x ], [ymin ,ymax ] , transform = trans , ** kwargs )
3492- l .y_isdata = False
34933529 self .add_line (l )
34943530 self .autoscale_view (scalex = scalex , scaley = False )
34953531 return l
@@ -3546,7 +3582,6 @@ def axhspan(self, ymin, ymax, xmin=0, xmax=1, **kwargs):
35463582 verts = (xmin , ymin ), (xmin , ymax ), (xmax , ymax ), (xmax , ymin )
35473583 p = mpatches .Polygon (verts , ** kwargs )
35483584 p .set_transform (trans )
3549- p .x_isdata = False
35503585 self .add_patch (p )
35513586 self .autoscale_view (scalex = False )
35523587 return p
@@ -3603,7 +3638,6 @@ def axvspan(self, xmin, xmax, ymin=0, ymax=1, **kwargs):
36033638 verts = [(xmin , ymin ), (xmin , ymax ), (xmax , ymax ), (xmax , ymin )]
36043639 p = mpatches .Polygon (verts , ** kwargs )
36053640 p .set_transform (trans )
3606- p .y_isdata = False
36073641 self .add_patch (p )
36083642 self .autoscale_view (scaley = False )
36093643 return p
@@ -3909,7 +3943,6 @@ def plot(self, *args, **kwargs):
39093943 self .add_line (line )
39103944 lines .append (line )
39113945
3912-
39133946 self .autoscale_view (scalex = scalex , scaley = scaley )
39143947 return lines
39153948
0 commit comments