@@ -4411,134 +4411,75 @@ def test_hist_step_bottom():
4411
4411
ax .hist (d1 , bottom = np .arange (10 ), histtype = "stepfilled" )
4412
4412
4413
4413
4414
- def test_hist_stepfilled_geometry ():
4415
- bins = [0 , 1 , 2 , 3 ]
4416
- data = [0 , 0 , 1 , 1 , 1 , 2 ]
4417
- _ , _ , (polygon , ) = plt .hist (data ,
4418
- bins = bins ,
4419
- histtype = 'stepfilled' )
4420
- xy = [[0 , 0 ], [0 , 2 ], [1 , 2 ], [1 , 3 ], [2 , 3 ], [2 , 1 ], [3 , 1 ],
4421
- [3 , 0 ], [2 , 0 ], [2 , 0 ], [1 , 0 ], [1 , 0 ], [0 , 0 ]]
4422
- assert_array_equal (polygon .get_xy (), xy )
4423
-
4424
-
4425
4414
def test_hist_step_geometry ():
4426
4415
bins = [0 , 1 , 2 , 3 ]
4427
4416
data = [0 , 0 , 1 , 1 , 1 , 2 ]
4428
- _ , _ , (polygon , ) = plt .hist (data ,
4429
- bins = bins ,
4430
- histtype = 'step' )
4431
- xy = [[0 , 0 ], [0 , 2 ], [1 , 2 ], [1 , 3 ], [2 , 3 ], [2 , 1 ], [3 , 1 ], [3 , 0 ]]
4432
- assert_array_equal (polygon .get_xy (), xy )
4417
+ top = [[0 , 0 ], [0 , 2 ], [1 , 2 ], [1 , 3 ], [2 , 3 ], [2 , 1 ], [3 , 1 ], [3 , 0 ]]
4418
+ bottom = [[2 , 0 ], [2 , 0 ], [1 , 0 ], [1 , 0 ], [0 , 0 ]]
4433
4419
4434
-
4435
- def test_hist_stepfilled_bottom_geometry ():
4436
- bins = [0 , 1 , 2 , 3 ]
4437
- data = [0 , 0 , 1 , 1 , 1 , 2 ]
4438
- _ , _ , (polygon , ) = plt .hist (data ,
4439
- bins = bins ,
4440
- bottom = [1 , 2 , 1.5 ],
4441
- histtype = 'stepfilled' )
4442
- xy = [[0 , 1 ], [0 , 3 ], [1 , 3 ], [1 , 5 ], [2 , 5 ], [2 , 2.5 ], [3 , 2.5 ],
4443
- [3 , 1.5 ], [2 , 1.5 ], [2 , 2 ], [1 , 2 ], [1 , 1 ], [0 , 1 ]]
4444
- assert_array_equal (polygon .get_xy (), xy )
4420
+ for histtype , xy in [('step' , top ), ('stepfilled' , top + bottom )]:
4421
+ _ , _ , (polygon , ) = plt .hist (data , bins = bins , histtype = histtype )
4422
+ assert_array_equal (polygon .get_xy (), xy )
4445
4423
4446
4424
4447
4425
def test_hist_step_bottom_geometry ():
4448
4426
bins = [0 , 1 , 2 , 3 ]
4449
4427
data = [0 , 0 , 1 , 1 , 1 , 2 ]
4450
- _ , _ , (polygon , ) = plt .hist (data ,
4451
- bins = bins ,
4452
- bottom = [1 , 2 , 1.5 ],
4453
- histtype = 'step' )
4454
- xy = [[0 , 1 ], [0 , 3 ], [1 , 3 ], [1 , 5 ], [2 , 5 ], [2 , 2.5 ], [3 , 2.5 ], [3 , 1.5 ]]
4455
- assert_array_equal (polygon .get_xy (), xy )
4456
-
4428
+ top = [[0 , 1 ], [0 , 3 ], [1 , 3 ], [1 , 5 ], [2 , 5 ], [2 , 2.5 ], [3 , 2.5 ], [3 , 1.5 ]]
4429
+ bottom = [[2 , 1.5 ], [2 , 2 ], [1 , 2 ], [1 , 1 ], [0 , 1 ]]
4457
4430
4458
- def test_hist_stacked_stepfilled_geometry ():
4459
- bins = [0 , 1 , 2 , 3 ]
4460
- data_1 = [0 , 0 , 1 , 1 , 1 , 2 ]
4461
- data_2 = [0 , 1 , 2 ]
4462
- _ , _ , patches = plt .hist ([data_1 , data_2 ],
4463
- bins = bins ,
4464
- stacked = True ,
4465
- histtype = 'stepfilled' )
4466
-
4467
- assert len (patches ) == 2
4468
-
4469
- polygon , = patches [0 ]
4470
- xy = [[0 , 0 ], [0 , 2 ], [1 , 2 ], [1 , 3 ], [2 , 3 ], [2 , 1 ], [3 , 1 ],
4471
- [3 , 0 ], [2 , 0 ], [2 , 0 ], [1 , 0 ], [1 , 0 ], [0 , 0 ]]
4472
- assert_array_equal (polygon .get_xy (), xy )
4473
-
4474
- polygon , = patches [1 ]
4475
- xy = [[0 , 2 ], [0 , 3 ], [1 , 3 ], [1 , 4 ], [2 , 4 ], [2 , 2 ], [3 , 2 ],
4476
- [3 , 1 ], [2 , 1 ], [2 , 3 ], [1 , 3 ], [1 , 2 ], [0 , 2 ]]
4477
- assert_array_equal (polygon .get_xy (), xy )
4431
+ for histtype , xy in [('step' , top ), ('stepfilled' , top + bottom )]:
4432
+ _ , _ , (polygon , ) = plt .hist (data , bins = bins , bottom = [1 , 2 , 1.5 ],
4433
+ histtype = histtype )
4434
+ assert_array_equal (polygon .get_xy (), xy )
4478
4435
4479
4436
4480
4437
def test_hist_stacked_step_geometry ():
4481
4438
bins = [0 , 1 , 2 , 3 ]
4482
4439
data_1 = [0 , 0 , 1 , 1 , 1 , 2 ]
4483
4440
data_2 = [0 , 1 , 2 ]
4484
- _ , _ , patches = plt .hist ([data_1 , data_2 ],
4485
- bins = bins ,
4486
- stacked = True ,
4487
- histtype = 'step' )
4488
-
4489
- assert len (patches ) == 2
4490
-
4491
- polygon , = patches [0 ]
4492
- xy = [[0 , 0 ], [0 , 2 ], [1 , 2 ], [1 , 3 ], [2 , 3 ], [2 , 1 ], [3 , 1 ], [3 , 0 ]]
4493
- assert_array_equal (polygon .get_xy (), xy )
4494
-
4495
- polygon , = patches [1 ]
4496
- xy = [[0 , 2 ], [0 , 3 ], [1 , 3 ], [1 , 4 ], [2 , 4 ], [2 , 2 ], [3 , 2 ], [3 , 1 ]]
4497
- assert_array_equal (polygon .get_xy (), xy )
4498
-
4499
-
4500
- def test_hist_stacked_stepfilled_bottom_geometry ():
4501
- bins = [0 , 1 , 2 , 3 ]
4502
- data_1 = [0 , 0 , 1 , 1 , 1 , 2 ]
4503
- data_2 = [0 , 1 , 2 ]
4504
- _ , _ , patches = plt .hist ([data_1 , data_2 ],
4505
- bins = bins ,
4506
- stacked = True ,
4507
- bottom = [1 , 2 , 1.5 ],
4508
- histtype = 'stepfilled' )
4509
-
4510
- assert len (patches ) == 2
4511
-
4512
- polygon , = patches [0 ]
4513
- xy = [[0 , 1 ], [0 , 3 ], [1 , 3 ], [1 , 5 ], [2 , 5 ], [2 , 2.5 ], [3 , 2.5 ],
4514
- [3 , 1.5 ], [2 , 1.5 ], [2 , 2 ], [1 , 2 ], [1 , 1 ], [0 , 1 ]]
4515
- assert_array_equal (polygon .get_xy (), xy )
4441
+ tops = [
4442
+ [[0 , 0 ], [0 , 2 ], [1 , 2 ], [1 , 3 ], [2 , 3 ], [2 , 1 ], [3 , 1 ], [3 , 0 ]],
4443
+ [[0 , 2 ], [0 , 3 ], [1 , 3 ], [1 , 4 ], [2 , 4 ], [2 , 2 ], [3 , 2 ], [3 , 1 ]],
4444
+ ]
4445
+ bottoms = [
4446
+ [[2 , 0 ], [2 , 0 ], [1 , 0 ], [1 , 0 ], [0 , 0 ]],
4447
+ [[2 , 1 ], [2 , 3 ], [1 , 3 ], [1 , 2 ], [0 , 2 ]],
4448
+ ]
4449
+ combined = [t + b for t , b in zip (tops , bottoms )]
4516
4450
4517
- polygon , = patches [1 ]
4518
- xy = [[0 , 3 ], [0 , 4 ], [1 , 4 ], [1 , 6 ], [2 , 6 ], [2 , 3.5 ], [3 , 3.5 ],
4519
- [3 , 2.5 ], [2 , 2.5 ], [2 , 5 ], [1 , 5 ], [1 , 3 ], [0 , 3 ]]
4520
- assert_array_equal (polygon .get_xy (), xy )
4451
+ for histtype , xy in [('step' , tops ), ('stepfilled' , combined )]:
4452
+ _ , _ , patches = plt .hist ([data_1 , data_2 ], bins = bins , stacked = True ,
4453
+ histtype = histtype )
4454
+ assert len (patches ) == 2
4455
+ polygon , = patches [0 ]
4456
+ assert_array_equal (polygon .get_xy (), xy [0 ])
4457
+ polygon , = patches [1 ]
4458
+ assert_array_equal (polygon .get_xy (), xy [1 ])
4521
4459
4522
4460
4523
4461
def test_hist_stacked_step_bottom_geometry ():
4524
4462
bins = [0 , 1 , 2 , 3 ]
4525
4463
data_1 = [0 , 0 , 1 , 1 , 1 , 2 ]
4526
4464
data_2 = [0 , 1 , 2 ]
4527
- _ , _ , patches = plt .hist ([data_1 , data_2 ],
4528
- bins = bins ,
4529
- stacked = True ,
4530
- bottom = [1 , 2 , 1.5 ],
4531
- histtype = 'step' )
4532
-
4533
- assert len (patches ) == 2
4534
-
4535
- polygon , = patches [0 ]
4536
- xy = [[0 , 1 ], [0 , 3 ], [1 , 3 ], [1 , 5 ], [2 , 5 ], [2 , 2.5 ], [3 , 2.5 ], [3 , 1.5 ]]
4537
- assert_array_equal (polygon .get_xy (), xy )
4538
-
4539
- polygon , = patches [1 ]
4540
- xy = [[0 , 3 ], [0 , 4 ], [1 , 4 ], [1 , 6 ], [2 , 6 ], [2 , 3.5 ], [3 , 3.5 ], [3 , 2.5 ]]
4541
- assert_array_equal (polygon .get_xy (), xy )
4465
+ tops = [
4466
+ [[0 , 1 ], [0 , 3 ], [1 , 3 ], [1 , 5 ], [2 , 5 ], [2 , 2.5 ], [3 , 2.5 ], [3 , 1.5 ]],
4467
+ [[0 , 3 ], [0 , 4 ], [1 , 4 ], [1 , 6 ], [2 , 6 ], [2 , 3.5 ], [3 , 3.5 ], [3 , 2.5 ]],
4468
+ ]
4469
+ bottoms = [
4470
+ [[2 , 1.5 ], [2 , 2 ], [1 , 2 ], [1 , 1 ], [0 , 1 ]],
4471
+ [[2 , 2.5 ], [2 , 5 ], [1 , 5 ], [1 , 3 ], [0 , 3 ]],
4472
+ ]
4473
+ combined = [t + b for t , b in zip (tops , bottoms )]
4474
+
4475
+ for histtype , xy in [('step' , tops ), ('stepfilled' , combined )]:
4476
+ _ , _ , patches = plt .hist ([data_1 , data_2 ], bins = bins , stacked = True ,
4477
+ bottom = [1 , 2 , 1.5 ], histtype = histtype )
4478
+ assert len (patches ) == 2
4479
+ polygon , = patches [0 ]
4480
+ assert_array_equal (polygon .get_xy (), xy [0 ])
4481
+ polygon , = patches [1 ]
4482
+ assert_array_equal (polygon .get_xy (), xy [1 ])
4542
4483
4543
4484
4544
4485
@image_comparison (['hist_stacked_bar' ])
0 commit comments