@@ -877,17 +877,24 @@ def test_collection_set_array():
877877
878878
879879def test_blended_collection_autolim ():
880- a = [1 , 2 , 4 ]
881- height = .2
880+ f , ax = plt .subplots ()
882881
883- xy_pairs = np .column_stack ([np .repeat (a , 2 ), np .tile ([0 , height ], len (a ))])
884- line_segs = xy_pairs .reshape ([len (a ), 2 , 2 ])
882+ # sample data to give initial data limits
883+ ax .plot ([2 , 3 , 4 ], [0.4 , 0.6 , 0.5 ])
884+ np .testing .assert_allclose ((ax .dataLim .xmin , ax .dataLim .xmax ), (2 , 4 ))
885+ data_ymin , data_ymax = ax .dataLim .ymin , ax .dataLim .ymax
885886
886- f , ax = plt .subplots ()
887+ # LineCollection with vertical lines spanning the Axes vertical, using transAxes
888+ x = [1 , 2 , 3 , 4 , 5 ]
889+ vertical_lines = [np .array ([[xi , 0 ], [xi , 1 ]]) for xi in x ]
887890 trans = mtransforms .blended_transform_factory (ax .transData , ax .transAxes )
888- ax .add_collection (LineCollection (line_segs , transform = trans ))
889- ax .autoscale_view (scalex = True , scaley = False )
890- np .testing .assert_allclose (ax .get_xlim (), [1. , 4. ])
891+ ax .add_collection (LineCollection (vertical_lines , transform = trans ))
892+
893+ # check that the x data limits are updated to include the LineCollection
894+ np .testing .assert_allclose ((ax .dataLim .xmin , ax .dataLim .xmax ), (1 , 5 ))
895+ # check that the y data limits are not updated (because they are not transData)
896+ np .testing .assert_allclose ((ax .dataLim .ymin , ax .dataLim .ymax ),
897+ (data_ymin , data_ymax ))
891898
892899
893900def test_singleton_autolim ():
0 commit comments