@@ -379,18 +379,73 @@ def test_parcats_dimensions_max():
379
379
assert [d .label for d in fig .data [0 ].dimensions ] == ["sex" , "smoker" , "day" , "size" ]
380
380
381
381
382
- def test_histfunc_hoverlabels ():
382
+ @pytest .mark .parametrize ("histfunc,y" , [(None , None ), ("count" , "tip" )])
383
+ def test_histfunc_hoverlabels_univariate (histfunc , y ):
384
+ def check_label (label , fig ):
385
+ assert fig .layout .yaxis .title .text == label
386
+ assert label + "=" in fig .data [0 ].hovertemplate
387
+
383
388
df = px .data .tips ()
384
- fig = px .histogram (df , x = "total_bill" )
385
- label = "count"
386
- assert fig .layout .yaxis .title .text == label
387
- assert label + "=" in fig .data [0 ].hovertemplate
388
389
389
- fig = px .histogram (df , x = "total_bill" , y = "tip" )
390
- label = "sum of tip"
391
- assert fig .layout .yaxis .title .text == label
392
- assert label + "=" in fig .data [0 ].hovertemplate
390
+ # base case, just "count" (note count(tip) is same as count())
391
+ fig = px .histogram (df , x = "total_bill" , y = y , histfunc = histfunc )
392
+ check_label ("count" , fig )
393
+
394
+ # without y, label is just histnorm
395
+ for histnorm in ["probability" , "percent" , "density" , "probability density" ]:
396
+ fig = px .histogram (
397
+ df , x = "total_bill" , y = y , histfunc = histfunc , histnorm = histnorm
398
+ )
399
+ check_label (histnorm , fig )
400
+
401
+ for histnorm in ["probability" , "percent" , "density" , "probability density" ]:
402
+ for barnorm in ["percent" , "fraction" ]:
403
+ fig = px .histogram (
404
+ df ,
405
+ x = "total_bill" ,
406
+ y = y ,
407
+ histfunc = histfunc ,
408
+ histnorm = histnorm ,
409
+ barnorm = barnorm ,
410
+ )
411
+ check_label ("%s (normalized as %s)" % (histnorm , barnorm ), fig )
412
+
413
+
414
+ def test_histfunc_hoverlabels_bivariate ():
415
+ def check_label (label , fig ):
416
+ assert fig .layout .yaxis .title .text == label
417
+ assert label + "=" in fig .data [0 ].hovertemplate
393
418
419
+ df = px .data .tips ()
420
+
421
+ # with y, should be same as forcing histfunc to sum
422
+ fig = px .histogram (df , x = "total_bill" , y = "tip" )
423
+ check_label ("sum of tip" , fig )
424
+
425
+ # change probability to fraction when histfunc is sum
426
+ fig = px .histogram (df , x = "total_bill" , y = "tip" , histnorm = "probability" )
427
+ check_label ("fraction of sum of tip" , fig )
428
+
429
+ # percent is percent
430
+ fig = px .histogram (df , x = "total_bill" , y = "tip" , histnorm = "percent" )
431
+ check_label ("percent of sum of tip" , fig )
432
+
433
+ # the other two are "weighted by"
434
+ for histnorm in ["density" , "probability density" ]:
435
+ fig = px .histogram (df , x = "total_bill" , y = "tip" , histnorm = histnorm )
436
+ check_label ("%s weighted by tip" % histnorm , fig )
437
+
438
+ # check a few "normalized by"
439
+ for histnorm in ["density" , "probability density" ]:
440
+ for barnorm in ["fraction" , "percent" ]:
441
+ fig = px .histogram (
442
+ df , x = "total_bill" , y = "tip" , histnorm = histnorm , barnorm = barnorm
443
+ )
444
+ check_label (
445
+ "%s weighted by tip (normalized as %s)" % (histnorm , barnorm ), fig
446
+ )
447
+
448
+ # these next two are weird but OK...
394
449
fig = px .histogram (
395
450
df ,
396
451
x = "total_bill" ,
@@ -399,9 +454,21 @@ def test_histfunc_hoverlabels():
399
454
histnorm = "probability" ,
400
455
barnorm = "percent" ,
401
456
)
402
- label = "probability of min of tip (normalized as percent)"
403
- assert fig .layout .yaxis .title .text == label
404
- assert label + "=" in fig .data [0 ].hovertemplate
457
+ check_label ("fraction of sum of min of tip (normalized as percent)" , fig )
458
+
459
+ fig = px .histogram (
460
+ df ,
461
+ x = "total_bill" ,
462
+ y = "tip" ,
463
+ histfunc = "avg" ,
464
+ histnorm = "percent" ,
465
+ barnorm = "fraction" ,
466
+ )
467
+ check_label ("percent of sum of avg of tip (normalized as fraction)" , fig )
468
+
469
+ # this next one is basically "never do this" but needs a defined behaviour
470
+ fig = px .histogram (df , x = "total_bill" , y = "tip" , histfunc = "max" , histnorm = "density" )
471
+ check_label ("density of max of tip" , fig )
405
472
406
473
407
474
def test_timeline ():
0 commit comments