@@ -270,51 +270,78 @@ def test_image_attributes(self):
270
270
271
271
272
272
def test_exclude_empty_subplots ():
273
- for k , fun , d in [
273
+ for k , fun , d , fun2 , d2 in [
274
274
(
275
275
"shapes" ,
276
276
go .Figure .add_shape ,
277
277
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" ),
278
289
),
279
- ("annotations" , go .Figure .add_annotation , dict (x = 1 , y = 2 , text = "A" )),
280
290
(
281
291
"images" ,
282
292
go .Figure .add_layout_image ,
283
293
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 ),
284
296
),
285
297
]:
286
298
# make a figure where not all the subplots are populated
287
299
fig = make_subplots (2 , 2 )
288
300
fig .add_trace (go .Scatter (x = [1 , 2 , 3 ], y = [5 , 1 , 2 ]), row = 1 , col = 1 )
289
301
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 )
290
303
# 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
294
307
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"
296
310
297
311
298
312
def test_no_exclude_empty_subplots ():
299
- for k , fun , d in [
313
+ for k , fun , d , fun2 , d2 in [
300
314
(
301
315
"shapes" ,
302
316
go .Figure .add_shape ,
303
317
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" ),
304
329
),
305
- ("annotations" , go .Figure .add_annotation , dict (x = 1 , y = 2 , text = "A" )),
306
330
(
307
331
"images" ,
308
332
go .Figure .add_layout_image ,
309
333
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 ),
310
336
),
311
337
]:
312
338
# make a figure where not all the subplots are populated
313
339
fig = make_subplots (2 , 2 )
314
340
fig .add_trace (go .Scatter (x = [1 , 2 , 3 ], y = [5 , 1 , 2 ]), row = 1 , col = 1 )
315
341
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
318
345
fun (fig , d , row = "all" , col = "all" , exclude_empty_subplots = False )
319
346
assert len (fig .layout [k ]) == 4
320
347
assert fig .layout [k ][0 ]["xref" ] == "x" and fig .layout [k ][0 ]["yref" ] == "y"
0 commit comments