@@ -899,17 +899,24 @@ def test_collection_set_array():
899
899
900
900
901
901
def test_blended_collection_autolim ():
902
- a = [1 , 2 , 4 ]
903
- height = .2
902
+ f , ax = plt .subplots ()
904
903
905
- xy_pairs = np .column_stack ([np .repeat (a , 2 ), np .tile ([0 , height ], len (a ))])
906
- line_segs = xy_pairs .reshape ([len (a ), 2 , 2 ])
904
+ # sample data to give initial data limits
905
+ ax .plot ([2 , 3 , 4 ], [0.4 , 0.6 , 0.5 ])
906
+ np .testing .assert_allclose ((ax .dataLim .xmin , ax .dataLim .xmax ), (2 , 4 ))
907
+ data_ymin , data_ymax = ax .dataLim .ymin , ax .dataLim .ymax
907
908
908
- f , ax = plt .subplots ()
909
+ # LineCollection with vertical lines spanning the Axes vertical, using transAxes
910
+ x = [1 , 2 , 3 , 4 , 5 ]
911
+ vertical_lines = [np .array ([[xi , 0 ], [xi , 1 ]]) for xi in x ]
909
912
trans = mtransforms .blended_transform_factory (ax .transData , ax .transAxes )
910
- ax .add_collection (LineCollection (line_segs , transform = trans ))
911
- ax .autoscale_view (scalex = True , scaley = False )
912
- np .testing .assert_allclose (ax .get_xlim (), [1. , 4. ])
913
+ ax .add_collection (LineCollection (vertical_lines , transform = trans ))
914
+
915
+ # check that the x data limits are updated to include the LineCollection
916
+ np .testing .assert_allclose ((ax .dataLim .xmin , ax .dataLim .xmax ), (1 , 5 ))
917
+ # check that the y data limits are not updated (because they are not transData)
918
+ np .testing .assert_allclose ((ax .dataLim .ymin , ax .dataLim .ymax ),
919
+ (data_ymin , data_ymax ))
913
920
914
921
915
922
def test_singleton_autolim ():
0 commit comments