@@ -6515,65 +6515,56 @@ def test_relim_collection():
65156515 fig , ax = plt .subplots ()
65166516 sc = ax .scatter ([1 , 2 , 3 ], [4 , 5 , 6 ])
65176517 ax .relim ()
6518- ax .autoscale_view ()
6519- xlim = ax .get_xlim ()
6520- ylim = ax .get_ylim ()
6521- assert xlim [0 ] <= 1 and xlim [1 ] >= 3
6522- assert ylim [0 ] <= 4 and ylim [1 ] >= 6
6518+ expected = sc .get_datalim (ax .transData )
6519+ assert_allclose (ax .dataLim .get_points (), expected .get_points ())
6520+ assert_allclose (ax .dataLim .minpos , expected .minpos )
65236521
65246522 # After updating offsets, relim should track the new data.
65256523 sc .set_offsets ([[10 , 20 ], [30 , 40 ]])
65266524 ax .relim ()
6527- ax .autoscale_view ()
6528- xlim = ax .get_xlim ()
6529- ylim = ax .get_ylim ()
6530- assert xlim [0 ] <= 10 and xlim [1 ] >= 30
6531- assert ylim [0 ] <= 20 and ylim [1 ] >= 40
6525+ expected = sc .get_datalim (ax .transData )
6526+ assert_allclose (ax .dataLim .get_points (), expected .get_points ())
6527+ assert_allclose (ax .dataLim .minpos , expected .minpos )
65326528
65336529 # visible_only=True should ignore hidden collections.
65346530 line , = ax .plot ([0 , 1 ], [0 , 1 ])
65356531 sc .set_visible (False )
65366532 ax .relim (visible_only = True )
6537- ax .autoscale_view ()
6538- xlim = ax .get_xlim ()
6539- ylim = ax .get_ylim ()
65406533 # With scatter hidden, limits should be driven by the line only.
6541- assert xlim [ 1 ] < 10
6542- assert ylim [ 1 ] < 10
6534+ assert_allclose ( ax . dataLim . get_points (), [[ 0 , 0 ], [ 1 , 1 ]])
6535+ assert_array_equal ( ax . dataLim . minpos , [ np . inf , np . inf ])
65436536
65446537
65456538def test_relim_collection_autolim_false ():
65466539 # GH#30859 - Collection added with autolim=False must not participate
65476540 # in relim() later.
65486541 import matplotlib .collections as mcollections
65496542 fig , ax = plt .subplots ()
6550- ax .set_xlim (0 , 1 )
6551- ax .set_ylim (0 , 1 )
6543+ ax .plot ([0 , 1 ], [0 , 1 ])
6544+ ax .relim ()
6545+ expected = ax .dataLim .frozen ()
65526546 # Build a collection far outside current limits and add it with autolim=False.
65536547 sc = mcollections .PathCollection ([])
65546548 sc .set_offsets ([[100 , 200 ], [300 , 400 ]])
65556549 ax .add_collection (sc , autolim = False )
65566550 ax .relim ()
6557- ax .autoscale_view ()
6558- # Limits must remain unchanged because autolim=False was requested.
6559- assert ax .get_xlim () == (0 , 1 )
6560- assert ax .get_ylim () == (0 , 1 )
6551+ # dataLim must remain unchanged because autolim=False was requested.
6552+ assert_allclose (ax .dataLim .get_points (), expected .get_points ())
6553+ assert_allclose (ax .dataLim .minpos , expected .minpos )
65616554
65626555
65636556def test_relim_collection_log_scale ():
65646557 # GH#30859 - relim() for Collection on a log-scaled axis should
6565- # correctly pick up minpos so that log scaling works properly .
6558+ # correctly propagate minpos into dataLim .
65666559 fig , ax = plt .subplots ()
65676560 ax .set_xscale ('log' )
65686561 ax .set_yscale ('log' )
65696562 sc = ax .scatter ([1e-3 , 1e-2 , 1e-1 ], [1e1 , 1e2 , 1e3 ])
65706563 sc .set_offsets ([[1e1 , 1e4 ], [1e2 , 1e5 ]])
65716564 ax .relim ()
6572- ax .autoscale_view ()
6573- xlim = ax .get_xlim ()
6574- ylim = ax .get_ylim ()
6575- assert xlim [0 ] <= 1e1 and xlim [1 ] >= 1e2
6576- assert ylim [0 ] <= 1e4 and ylim [1 ] >= 1e5
6565+ expected = sc .get_datalim (ax .transData )
6566+ assert_allclose (ax .dataLim .get_points (), expected .get_points ())
6567+ assert_allclose (ax .dataLim .minpos , expected .minpos )
65776568
65786569
65796570def test_text_labelsize ():
0 commit comments