File tree Expand file tree Collapse file tree 2 files changed +34
-4
lines changed Expand file tree Collapse file tree 2 files changed +34
-4
lines changed Original file line number Diff line number Diff line change @@ -1590,9 +1590,11 @@ def add_container(self, container):
1590
1590
container .set_remove_method (lambda h : self .containers .remove (h ))
1591
1591
return container
1592
1592
1593
- def relim (self ):
1593
+ def relim (self , visible_only = False ):
1594
1594
"""
1595
- Recompute the data limits based on current artists.
1595
+ Recompute the data limits based on current artists. If you want to exclude
1596
+ invisible artists from the calculation, set
1597
+ `visible_only=True`
1596
1598
1597
1599
At present, :class:`~matplotlib.collections.Collection`
1598
1600
instances are not supported.
@@ -1604,10 +1606,12 @@ def relim(self):
1604
1606
self .ignore_existing_data_limits = True
1605
1607
1606
1608
for line in self .lines :
1607
- self ._update_line_limits (line )
1609
+ if not visible_only or line .get_visible ():
1610
+ self ._update_line_limits (line )
1608
1611
1609
1612
for p in self .patches :
1610
- self ._update_patch_limits (p )
1613
+ if not visible_only or p .get_visible ():
1614
+ self ._update_patch_limits (p )
1611
1615
1612
1616
def update_datalim (self , xys , updatex = True , updatey = True ):
1613
1617
"""
Original file line number Diff line number Diff line change @@ -1737,6 +1737,32 @@ def test_empty_shared_subplots():
1737
1737
assert y1 >= 6
1738
1738
1739
1739
1740
+ @cleanup
1741
+ def test_relim_visible_only ():
1742
+ x1 = (0. , 10. )
1743
+ y1 = (0. , 10. )
1744
+ x2 = (- 10. , 20. )
1745
+ y2 = (- 10. , 30. )
1746
+
1747
+ fig = matplotlib .figure .Figure ()
1748
+ ax = fig .add_subplot (111 )
1749
+ ax .plot (x1 , y1 )
1750
+ assert ax .get_xlim () == x1
1751
+ assert ax .get_ylim () == y1
1752
+ l = ax .plot (x2 , y2 )
1753
+ assert ax .get_xlim () == x2
1754
+ assert ax .get_ylim () == y2
1755
+ l [0 ].set_visible (False )
1756
+ assert ax .get_xlim () == x2
1757
+ assert ax .get_ylim () == y2
1758
+
1759
+ ax .relim (visible_only = True )
1760
+ ax .autoscale_view ()
1761
+
1762
+ assert ax .get_xlim () == x1
1763
+ assert ax .get_ylim () == y1
1764
+
1765
+
1740
1766
if __name__ == '__main__' :
1741
1767
import nose
1742
1768
nose .runmodule (argv = ['-s' , '--with-doctest' ], exit = False )
You can’t perform that action at this time.
0 commit comments