Skip to content

Commit ca946ac

Browse files
authored
Merge pull request #27447 from QuLogic/fewer-tests
TST: Compress some hist geometry tests
2 parents 5f52428 + 092a400 commit ca946ac

File tree

1 file changed

+46
-105
lines changed

1 file changed

+46
-105
lines changed

lib/matplotlib/tests/test_axes.py

Lines changed: 46 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -4411,134 +4411,75 @@ def test_hist_step_bottom():
44114411
ax.hist(d1, bottom=np.arange(10), histtype="stepfilled")
44124412

44134413

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-
44254414
def test_hist_step_geometry():
44264415
bins = [0, 1, 2, 3]
44274416
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]]
44334419

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)
44454423

44464424

44474425
def test_hist_step_bottom_geometry():
44484426
bins = [0, 1, 2, 3]
44494427
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]]
44574430

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)
44784435

44794436

44804437
def test_hist_stacked_step_geometry():
44814438
bins = [0, 1, 2, 3]
44824439
data_1 = [0, 0, 1, 1, 1, 2]
44834440
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)]
45164450

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])
45214459

45224460

45234461
def test_hist_stacked_step_bottom_geometry():
45244462
bins = [0, 1, 2, 3]
45254463
data_1 = [0, 0, 1, 1, 1, 2]
45264464
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])
45424483

45434484

45444485
@image_comparison(['hist_stacked_bar'])

0 commit comments

Comments
 (0)