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