@@ -1461,17 +1461,52 @@ def add_line(self, line):
1461
1461
1462
1462
self ._update_line_limits (line )
1463
1463
if not line .get_label ():
1464
- line .set_label ('_line%d' % len (self .lines ))
1464
+ line .set_label ('_line%d' % len (self .lines ))
1465
1465
self .lines .append (line )
1466
1466
line ._remove_method = lambda h : self .lines .remove (h )
1467
1467
return line
1468
1468
1469
1469
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 )
1475
1510
self .ignore_existing_data_limits = False
1476
1511
1477
1512
def add_patch (self , p ):
@@ -1507,11 +1542,14 @@ def _update_patch_limits(self, patch):
1507
1542
if vertices .size > 0 :
1508
1543
xys = patch .get_patch_transform ().transform (vertices )
1509
1544
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 )
1515
1553
1516
1554
1517
1555
def add_table (self , tab ):
@@ -1599,13 +1637,13 @@ def _process_unit_info(self, xdata=None, ydata=None, kwargs=None):
1599
1637
if xdata is not None :
1600
1638
# we only need to update if there is nothing set yet.
1601
1639
if not self .xaxis .have_units ():
1602
- self .xaxis .update_units (xdata )
1640
+ self .xaxis .update_units (xdata )
1603
1641
#print '\tset from xdata', self.xaxis.units
1604
1642
1605
1643
if ydata is not None :
1606
1644
# we only need to update if there is nothing set yet.
1607
1645
if not self .yaxis .have_units ():
1608
- self .yaxis .update_units (ydata )
1646
+ self .yaxis .update_units (ydata )
1609
1647
#print '\tset from ydata', self.yaxis.units
1610
1648
1611
1649
# process kwargs 2nd since these will override default units
@@ -3424,7 +3462,6 @@ def axhline(self, y=0, xmin=0, xmax=1, **kwargs):
3424
3462
trans = mtransforms .blended_transform_factory (
3425
3463
self .transAxes , self .transData )
3426
3464
l = mlines .Line2D ([xmin ,xmax ], [y ,y ], transform = trans , ** kwargs )
3427
- l .x_isdata = False
3428
3465
self .add_line (l )
3429
3466
self .autoscale_view (scalex = False , scaley = scaley )
3430
3467
return l
@@ -3489,7 +3526,6 @@ def axvline(self, x=0, ymin=0, ymax=1, **kwargs):
3489
3526
trans = mtransforms .blended_transform_factory (
3490
3527
self .transData , self .transAxes )
3491
3528
l = mlines .Line2D ([x ,x ], [ymin ,ymax ] , transform = trans , ** kwargs )
3492
- l .y_isdata = False
3493
3529
self .add_line (l )
3494
3530
self .autoscale_view (scalex = scalex , scaley = False )
3495
3531
return l
@@ -3546,7 +3582,6 @@ def axhspan(self, ymin, ymax, xmin=0, xmax=1, **kwargs):
3546
3582
verts = (xmin , ymin ), (xmin , ymax ), (xmax , ymax ), (xmax , ymin )
3547
3583
p = mpatches .Polygon (verts , ** kwargs )
3548
3584
p .set_transform (trans )
3549
- p .x_isdata = False
3550
3585
self .add_patch (p )
3551
3586
self .autoscale_view (scalex = False )
3552
3587
return p
@@ -3603,7 +3638,6 @@ def axvspan(self, xmin, xmax, ymin=0, ymax=1, **kwargs):
3603
3638
verts = [(xmin , ymin ), (xmin , ymax ), (xmax , ymax ), (xmax , ymin )]
3604
3639
p = mpatches .Polygon (verts , ** kwargs )
3605
3640
p .set_transform (trans )
3606
- p .y_isdata = False
3607
3641
self .add_patch (p )
3608
3642
self .autoscale_view (scaley = False )
3609
3643
return p
@@ -3909,7 +3943,6 @@ def plot(self, *args, **kwargs):
3909
3943
self .add_line (line )
3910
3944
lines .append (line )
3911
3945
3912
-
3913
3946
self .autoscale_view (scalex = scalex , scaley = scaley )
3914
3947
return lines
3915
3948
0 commit comments