Skip to content

Commit 71dc2d6

Browse files
committed
Fix stairs() tests
1 parent 5173cda commit 71dc2d6

File tree

2 files changed

+21
-23
lines changed

2 files changed

+21
-23
lines changed

lib/matplotlib/patches.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,8 @@ class StepPatch(PathPatch):
996996
The path is unclosed. It starts and stops at baseline.
997997
"""
998998

999+
_edge_default = False
1000+
9991001
@docstring.dedent_interpd
10001002
def __init__(self, values, edges, *,
10011003
orientation='vertical', baseline=0, **kwargs):

lib/matplotlib/tests/test_axes.py

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1806,25 +1806,23 @@ def test_hist_zorder(histtype, zorder):
18061806
assert patch.get_zorder() == zorder
18071807

18081808

1809-
@check_figures_equal()
1809+
@check_figures_equal(extensions=['png'])
18101810
def test_stairs(fig_test, fig_ref):
18111811
import matplotlib.lines as mlines
18121812
y = np.array([6, 14, 32, 37, 48, 32, 21, 4]) # hist
18131813
x = np.array([1., 2., 3., 4., 5., 6., 7., 8., 9.]) # bins
18141814

1815-
fig_test, test_axes = plt.subplots(3, 2)
1816-
test_axes = test_axes.flatten()
1815+
test_axes = fig_test.subplots(3, 2).flatten()
18171816
test_axes[0].stairs(y, x, baseline=None)
18181817
test_axes[1].stairs(y, x, baseline=None, orientation='horizontal')
18191818
test_axes[2].stairs(y, x)
18201819
test_axes[3].stairs(y, x, orientation='horizontal')
18211820
test_axes[4].stairs(y, x)
18221821
test_axes[4].semilogy()
18231822
test_axes[5].stairs(y, x, orientation='horizontal')
1824-
test_axes[5].semilogy()
1823+
test_axes[5].semilogx()
18251824

1826-
fig_ref, ref_axes = plt.subplots(3, 2)
1827-
ref_axes = ref_axes.flatten()
1825+
ref_axes = fig_ref.subplots(3, 2).flatten()
18281826
ref_axes[0].plot(x, np.append(y, y[-1]), drawstyle='steps-post')
18291827
ref_axes[1].plot(np.append(y[0], y), x, drawstyle='steps-post')
18301828

@@ -1849,22 +1847,20 @@ def test_stairs(fig_test, fig_ref):
18491847
ref_axes[5].semilogx()
18501848

18511849

1852-
@check_figures_equal()
1850+
@check_figures_equal(extensions=['png'])
18531851
def test_stairs_fill(fig_test, fig_ref):
18541852
h, bins = [1, 2, 3, 4, 2], [0, 1, 2, 3, 4, 5]
18551853
bs = -2
18561854
# Test
1857-
fig_test, test_axes = plt.subplots(2, 2)
1858-
test_axes = test_axes.flatten()
1855+
test_axes = fig_test.subplots(2, 2).flatten()
18591856
test_axes[0].stairs(h, bins, fill=True)
18601857
test_axes[1].stairs(h, bins, orientation='horizontal', fill=True)
18611858
test_axes[2].stairs(h, bins, baseline=bs, fill=True)
18621859
test_axes[3].stairs(h, bins, baseline=bs, orientation='horizontal',
1863-
fill=True)
1860+
fill=True)
18641861

18651862
# # Ref
1866-
fig_ref, ref_axes = plt.subplots(2, 2)
1867-
ref_axes = ref_axes.flatten()
1863+
ref_axes = fig_ref.subplots(2, 2).flatten()
18681864
ref_axes[0].fill_between(bins, np.append(h, h[-1]), step='post')
18691865
ref_axes[0].set_ylim(0, None)
18701866
ref_axes[1].fill_betweenx(bins, np.append(h, h[-1]), step='post')
@@ -1877,10 +1873,10 @@ def test_stairs_fill(fig_test, fig_ref):
18771873
ref_axes[3].set_xlim(bs, None)
18781874

18791875

1880-
@check_figures_equal()
1876+
@check_figures_equal(extensions=['png'])
18811877
def test_stairs_update(fig_test, fig_ref):
18821878
# Test
1883-
fig_test, test_ax = plt.subplots()
1879+
test_ax = fig_test.add_subplot()
18841880
h = test_ax.stairs([1, 2, 3])
18851881
h.set_values([3, 2, 1])
18861882
h.set_edges(np.arange(4)+2)
@@ -1893,30 +1889,30 @@ def test_stairs_update(fig_test, fig_ref):
18931889
assert h.get_baseline() == -2
18941890

18951891
# # Ref
1896-
fig_ref, ref_ax = plt.subplots()
1892+
ref_ax = fig_ref.add_subplot()
18971893
h = ref_ax.stairs([1, 2, 3], baseline=-2)
18981894

18991895

1900-
@pytest.mark.xfail
19011896
def test_stairs_invalid_nan():
1902-
plt.stairs([1, 2], [0, np.nan, 1])
1897+
with pytest.raises(ValueError, match='Nan values in "edges"'):
1898+
plt.stairs([1, 2], [0, np.nan, 1])
19031899

19041900

1905-
@pytest.mark.xfail
19061901
def test_stairs_invalid_mismatch():
1907-
plt.stairs([1, 2], [0, 1])
1902+
with pytest.raises(ValueError, match='Size mismatch'):
1903+
plt.stairs([1, 2], [0, 1])
19081904

19091905

1910-
@pytest.mark.xfail
19111906
def test_stairs_invalid_update():
19121907
h = plt.stairs([1, 2], [0, 1, 2])
1913-
h.set_edges([1, np.nan, 2])
1908+
with pytest.raises(ValueError, match='Nan values in "edges"'):
1909+
h.set_edges([1, np.nan, 2])
19141910

19151911

1916-
@pytest.mark.xfail
19171912
def test_stairs_invalid_update2():
19181913
h = plt.stairs([1, 2], [0, 1, 2])
1919-
h.set_edges(np.arange(5))
1914+
with pytest.raises(ValueError, match='Size mismatch'):
1915+
h.set_edges(np.arange(5))
19201916

19211917

19221918
@image_comparison(['test_stairs_options.png'], remove_text=True)

0 commit comments

Comments
 (0)