@@ -270,51 +270,78 @@ def test_image_attributes(self):
270270
271271
272272def test_exclude_empty_subplots ():
273- for k , fun , d in [
273+ for k , fun , d , fun2 , d2 in [
274274 (
275275 "shapes" ,
276276 go .Figure .add_shape ,
277277 dict (type = "rect" , x0 = 1.5 , x1 = 2.5 , y0 = 3.5 , y1 = 4.5 ),
278+ # add a different type to make the check easier (otherwise we might
279+ # mix up the objects added before and after fun was run)
280+ go .Figure .add_annotation ,
281+ dict (x = 1 , y = 2 , text = "A" ),
282+ ),
283+ (
284+ "annotations" ,
285+ go .Figure .add_annotation ,
286+ dict (x = 1 , y = 2 , text = "A" ),
287+ go .Figure .add_layout_image ,
288+ dict (x = 3 , y = 4 , sizex = 2 , sizey = 3 , source = "test" ),
278289 ),
279- ("annotations" , go .Figure .add_annotation , dict (x = 1 , y = 2 , text = "A" )),
280290 (
281291 "images" ,
282292 go .Figure .add_layout_image ,
283293 dict (x = 3 , y = 4 , sizex = 2 , sizey = 3 , source = "test" ),
294+ go .Figure .add_shape ,
295+ dict (type = "rect" , x0 = 1.5 , x1 = 2.5 , y0 = 3.5 , y1 = 4.5 ),
284296 ),
285297 ]:
286298 # make a figure where not all the subplots are populated
287299 fig = make_subplots (2 , 2 )
288300 fig .add_trace (go .Scatter (x = [1 , 2 , 3 ], y = [5 , 1 , 2 ]), row = 1 , col = 1 )
289301 fig .add_trace (go .Scatter (x = [1 , 2 , 3 ], y = [2 , 1 , - 7 ]), row = 2 , col = 2 )
302+ fun2 (fig , d2 , row = 1 , col = 2 )
290303 # add a thing to all subplots but make sure it only goes on the
291- # plots without data
292- fun (fig , d , row = "all" , col = "all" , exclude_empty_subplots = True )
293- assert len (fig .layout [k ]) == 2
304+ # plots without data or layout objects
305+ fun (fig , d , row = "all" , col = "all" , exclude_empty_subplots = "anything_truthy" )
306+ assert len (fig .layout [k ]) == 3
294307 assert fig .layout [k ][0 ]["xref" ] == "x" and fig .layout [k ][0 ]["yref" ] == "y"
295- assert fig .layout [k ][1 ]["xref" ] == "x4" and fig .layout [k ][1 ]["yref" ] == "y4"
308+ assert fig .layout [k ][1 ]["xref" ] == "x2" and fig .layout [k ][1 ]["yref" ] == "y2"
309+ assert fig .layout [k ][2 ]["xref" ] == "x4" and fig .layout [k ][2 ]["yref" ] == "y4"
296310
297311
298312def test_no_exclude_empty_subplots ():
299- for k , fun , d in [
313+ for k , fun , d , fun2 , d2 in [
300314 (
301315 "shapes" ,
302316 go .Figure .add_shape ,
303317 dict (type = "rect" , x0 = 1.5 , x1 = 2.5 , y0 = 3.5 , y1 = 4.5 ),
318+ # add a different type to make the check easier (otherwise we might
319+ # mix up the objects added before and after fun was run)
320+ go .Figure .add_annotation ,
321+ dict (x = 1 , y = 2 , text = "A" ),
322+ ),
323+ (
324+ "annotations" ,
325+ go .Figure .add_annotation ,
326+ dict (x = 1 , y = 2 , text = "A" ),
327+ go .Figure .add_layout_image ,
328+ dict (x = 3 , y = 4 , sizex = 2 , sizey = 3 , source = "test" ),
304329 ),
305- ("annotations" , go .Figure .add_annotation , dict (x = 1 , y = 2 , text = "A" )),
306330 (
307331 "images" ,
308332 go .Figure .add_layout_image ,
309333 dict (x = 3 , y = 4 , sizex = 2 , sizey = 3 , source = "test" ),
334+ go .Figure .add_shape ,
335+ dict (type = "rect" , x0 = 1.5 , x1 = 2.5 , y0 = 3.5 , y1 = 4.5 ),
310336 ),
311337 ]:
312338 # make a figure where not all the subplots are populated
313339 fig = make_subplots (2 , 2 )
314340 fig .add_trace (go .Scatter (x = [1 , 2 , 3 ], y = [5 , 1 , 2 ]), row = 1 , col = 1 )
315341 fig .add_trace (go .Scatter (x = [1 , 2 , 3 ], y = [2 , 1 , - 7 ]), row = 2 , col = 2 )
316- # add a thing to all subplots and make sure it even goes on the
317- # plots without data
342+ fun2 (fig , d2 , row = 1 , col = 2 )
343+ # add a thing to all subplots but make sure it only goes on the
344+ # plots without data or layout objects
318345 fun (fig , d , row = "all" , col = "all" , exclude_empty_subplots = False )
319346 assert len (fig .layout [k ]) == 4
320347 assert fig .layout [k ][0 ]["xref" ] == "x" and fig .layout [k ][0 ]["yref" ] == "y"
0 commit comments