Skip to content

Commit dcc72bd

Browse files
committed
Test geometry of step(filled) histograms
1 parent 56905d2 commit dcc72bd

File tree

1 file changed

+131
-0
lines changed

1 file changed

+131
-0
lines changed

lib/matplotlib/tests/test_axes.py

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3288,6 +3288,137 @@ def test_hist_step_bottom():
32883288
ax = fig.add_subplot(111)
32893289
ax.hist(d1, bottom=np.arange(10), histtype="stepfilled")
32903290

3291+
def test_hist_stepfilled_geometry():
3292+
bins = [0, 1, 2, 3]
3293+
data = [0, 0, 1, 1, 1, 2]
3294+
_, _, (polygon, ) = plt.hist(data,
3295+
bins=bins,
3296+
histtype='stepfilled')
3297+
3298+
xy = [[0, 0], [0, 2], [1, 2], [1, 3], [2, 3], [2, 1], [3, 1],
3299+
[3, 0], [2, 0], [2, 0], [1, 0], [1, 0], [0, 0]]
3300+
3301+
assert (polygon.get_xy() == xy).all()
3302+
3303+
def test_hist_step_geometry():
3304+
bins = [0, 1, 2, 3]
3305+
data = [0, 0, 1, 1, 1, 2]
3306+
_, _, (polygon, ) = plt.hist(data,
3307+
bins=bins,
3308+
histtype='step')
3309+
3310+
xy = [[0, 0], [0, 2], [1, 2], [1, 3], [2, 3], [2, 1], [3, 1], [3, 0]]
3311+
3312+
assert (polygon.get_xy() == xy).all()
3313+
3314+
def test_hist_stepfilled_bottom_geometry():
3315+
bins = [0, 1, 2, 3]
3316+
data = [0, 0, 1, 1, 1, 2]
3317+
_, _, (polygon, ) = plt.hist(data,
3318+
bins=bins,
3319+
bottom=[1, 2, 1.5],
3320+
histtype='stepfilled')
3321+
3322+
xy = [[0, 1], [0, 3], [1, 3], [1, 5], [2, 5], [2, 2.5], [3, 2.5],
3323+
[3, 1.5], [2, 1.5], [2, 2], [1, 2], [1, 1], [0, 1]]
3324+
3325+
assert (polygon.get_xy() == xy).all()
3326+
3327+
def test_hist_step_bottom_geometry():
3328+
bins = [0, 1, 2, 3]
3329+
data = [0, 0, 1, 1, 1, 2]
3330+
_, _, (polygon, ) = plt.hist(data,
3331+
bins=bins,
3332+
bottom=[1, 2, 1.5],
3333+
histtype='step')
3334+
3335+
xy = [[0, 1], [0, 3], [1, 3], [1, 5], [2, 5], [2, 2.5], [3, 2.5], [3, 1.5]]
3336+
3337+
assert (polygon.get_xy() == xy).all()
3338+
3339+
def test_hist_stacked_stepfilled_geometry():
3340+
bins = [0, 1, 2, 3]
3341+
data_1 = [0, 0, 1, 1, 1, 2]
3342+
data_2 = [0, 1, 2]
3343+
_, _, patches = plt.hist([data_1, data_2],
3344+
bins=bins,
3345+
stacked=True,
3346+
histtype='stepfilled')
3347+
3348+
assert len(patches) == 2
3349+
3350+
polygon, = patches[0]
3351+
xy = [[0, 0], [0, 2], [1, 2], [1, 3], [2, 3], [2, 1], [3, 1],
3352+
[3, 0], [2, 0], [2, 0], [1, 0], [1, 0], [0, 0]]
3353+
assert (polygon.get_xy() == xy).all()
3354+
3355+
polygon, = patches[1]
3356+
xy = [[0, 2], [0, 3], [1, 3], [1, 4], [2, 4], [2, 2], [3, 2],
3357+
[3, 1], [2, 1], [2, 3], [1, 3], [1, 2], [0, 2]]
3358+
assert (polygon.get_xy() == xy).all()
3359+
3360+
def test_hist_stacked_step_geometry():
3361+
bins = [0, 1, 2, 3]
3362+
data_1 = [0, 0, 1, 1, 1, 2]
3363+
data_2 = [0, 1, 2]
3364+
_, _, patches = plt.hist([data_1, data_2],
3365+
bins=bins,
3366+
stacked=True,
3367+
histtype='step')
3368+
3369+
assert len(patches) == 2
3370+
3371+
polygon, = patches[0]
3372+
xy = [[0, 0], [0, 2], [1, 2], [1, 3], [2, 3], [2, 1], [3, 1], [3, 0]]
3373+
assert (polygon.get_xy() == xy).all()
3374+
3375+
polygon, = patches[1]
3376+
xy = [[0, 2], [0, 3], [1, 3], [1, 4], [2, 4], [2, 2], [3, 2], [3, 1]]
3377+
assert (polygon.get_xy() == xy).all()
3378+
3379+
3380+
def test_hist_stacked_stepfilled_bottom_geometry():
3381+
bins = [0, 1, 2, 3]
3382+
data_1 = [0, 0, 1, 1, 1, 2]
3383+
data_2 = [0, 1, 2]
3384+
_, _, patches = plt.hist([data_1, data_2],
3385+
bins=bins,
3386+
stacked=True,
3387+
bottom=[1, 2, 1.5],
3388+
histtype='stepfilled')
3389+
3390+
assert len(patches) == 2
3391+
3392+
polygon, = patches[0]
3393+
xy = [[0, 1], [0, 3], [1, 3], [1, 5], [2, 5], [2, 2.5], [3, 2.5],
3394+
[3, 1.5], [2, 1.5], [2, 2], [1, 2], [1, 1], [0, 1]]
3395+
assert (polygon.get_xy() == xy).all()
3396+
3397+
polygon, = patches[1]
3398+
xy = [[0, 3], [0, 4], [1, 4], [1, 6], [2, 6], [2, 3.5], [3, 3.5],
3399+
[3, 2.5], [2, 2.5], [2, 5], [1, 5], [1, 3], [0, 3]]
3400+
assert (polygon.get_xy() == xy).all()
3401+
3402+
3403+
def test_hist_stacked_step_bottom_geometry():
3404+
bins = [0, 1, 2, 3]
3405+
data_1 = [0, 0, 1, 1, 1, 2]
3406+
data_2 = [0, 1, 2]
3407+
_, _, patches = plt.hist([data_1, data_2],
3408+
bins=bins,
3409+
stacked=True,
3410+
bottom=[1, 2, 1.5],
3411+
histtype='step')
3412+
3413+
assert len(patches) == 2
3414+
3415+
polygon, = patches[0]
3416+
xy = [[0, 1], [0, 3], [1, 3], [1, 5], [2, 5], [2, 2.5], [3, 2.5], [3, 1.5]]
3417+
assert (polygon.get_xy() == xy).all()
3418+
3419+
polygon, = patches[1]
3420+
xy = [[0, 3], [0, 4], [1, 4], [1, 6], [2, 6], [2, 3.5], [3, 3.5], [3, 2.5]]
3421+
assert (polygon.get_xy() == xy).all()
32913422

32923423
@image_comparison(['hist_stacked_bar'])
32933424
def test_hist_stacked_bar():

0 commit comments

Comments
 (0)