@@ -1806,82 +1806,84 @@ def test_hist_zorder(histtype, zorder):
1806
1806
assert patch .get_zorder () == zorder
1807
1807
1808
1808
1809
- @check_figures_equal ()
1809
+ @check_figures_equal (extensions = [ 'png' ] )
1810
1810
def test_stairs (fig_test , fig_ref ):
1811
1811
import matplotlib .lines as mlines
1812
1812
y = np .array ([6 , 14 , 32 , 37 , 48 , 32 , 21 , 4 ]) # hist
1813
1813
x = np .array ([1. , 2. , 3. , 4. , 5. , 6. , 7. , 8. , 9. ]) # bins
1814
1814
1815
- fig_test , test_axes = plt .subplots (3 , 2 )
1816
- test_axes = test_axes .flatten ()
1815
+ test_axes = fig_test .subplots (3 , 2 ).flatten ()
1817
1816
test_axes [0 ].stairs (y , x , baseline = None )
1818
1817
test_axes [1 ].stairs (y , x , baseline = None , orientation = 'horizontal' )
1819
1818
test_axes [2 ].stairs (y , x )
1820
1819
test_axes [3 ].stairs (y , x , orientation = 'horizontal' )
1821
1820
test_axes [4 ].stairs (y , x )
1822
1821
test_axes [4 ].semilogy ()
1823
1822
test_axes [5 ].stairs (y , x , orientation = 'horizontal' )
1824
- test_axes [5 ].semilogy ()
1823
+ test_axes [5 ].semilogx ()
1825
1824
1826
- fig_ref , ref_axes = plt .subplots (3 , 2 )
1827
- ref_axes = ref_axes .flatten ()
1828
- ref_axes [0 ].plot (x , np .append (y , y [- 1 ]), drawstyle = 'steps-post' )
1829
- ref_axes [1 ].plot (np .append (y [0 ], y ), x , drawstyle = 'steps-post' )
1825
+ # defaults of `PathPatch` to be used for all following Line2D
1826
+ style = {'solid_joinstyle' : 'miter' , 'solid_capstyle' : 'butt' }
1830
1827
1831
- ref_axes [2 ].plot (x , np .append (y , y [- 1 ]), drawstyle = 'steps-post' )
1832
- ref_axes [2 ].add_line (mlines .Line2D ([x [0 ], x [0 ]], [0 , y [0 ]]))
1833
- ref_axes [2 ].add_line (mlines .Line2D ([x [- 1 ], x [- 1 ]], [0 , y [- 1 ]]))
1828
+ ref_axes = fig_ref .subplots (3 , 2 ).flatten ()
1829
+ ref_axes [0 ].plot (x , np .append (y , y [- 1 ]), drawstyle = 'steps-post' , ** style )
1830
+ ref_axes [1 ].plot (np .append (y [0 ], y ), x , drawstyle = 'steps-post' , **style )
1831
+
1832
+ ref_axes [2 ].plot (x , np .append (y , y [- 1 ]), drawstyle = 'steps-post' , ** style )
1833
+ ref_axes [2 ].add_line (mlines .Line2D ([x [0 ], x [0 ]], [0 , y [0 ]], ** style ))
1834
+ ref_axes [2 ].add_line (mlines .Line2D ([x [- 1 ], x [- 1 ]], [0 , y [- 1 ]], ** style ))
1834
1835
ref_axes [2 ].set_ylim (0 , None )
1835
1836
1836
- ref_axes [3 ].plot (np .append (y [0 ], y ), x , drawstyle = 'steps-post' )
1837
- ref_axes [3 ].add_line (mlines .Line2D ([0 , y [0 ]], [x [0 ], x [0 ]]))
1838
- ref_axes [3 ].add_line (mlines .Line2D ([0 , y [- 1 ]], [x [- 1 ], x [- 1 ]]))
1837
+ ref_axes [3 ].plot (np .append (y [0 ], y ), x , drawstyle = 'steps-post' , ** style )
1838
+ ref_axes [3 ].add_line (mlines .Line2D ([0 , y [0 ]], [x [0 ], x [0 ]], ** style ))
1839
+ ref_axes [3 ].add_line (mlines .Line2D ([0 , y [- 1 ]], [x [- 1 ], x [- 1 ]], ** style ))
1839
1840
ref_axes [3 ].set_xlim (0 , None )
1840
1841
1841
- ref_axes [4 ].plot (x , np .append (y , y [- 1 ]), drawstyle = 'steps-post' )
1842
- ref_axes [4 ].add_line (mlines .Line2D ([x [0 ], x [0 ]], [0 , y [0 ]]))
1843
- ref_axes [4 ].add_line (mlines .Line2D ([x [- 1 ], x [- 1 ]], [0 , y [- 1 ]]))
1842
+ ref_axes [4 ].plot (x , np .append (y , y [- 1 ]), drawstyle = 'steps-post' , ** style )
1843
+ ref_axes [4 ].add_line (mlines .Line2D ([x [0 ], x [0 ]], [0 , y [0 ]], ** style ))
1844
+ ref_axes [4 ].add_line (mlines .Line2D ([x [- 1 ], x [- 1 ]], [0 , y [- 1 ]], ** style ))
1844
1845
ref_axes [4 ].semilogy ()
1845
1846
1846
- ref_axes [5 ].plot (np .append (y [0 ], y ), x , drawstyle = 'steps-post' )
1847
- ref_axes [5 ].add_line (mlines .Line2D ([0 , y [0 ]], [x [0 ], x [0 ]]))
1848
- ref_axes [5 ].add_line (mlines .Line2D ([0 , y [- 1 ]], [x [- 1 ], x [- 1 ]]))
1847
+ ref_axes [5 ].plot (np .append (y [0 ], y ), x , drawstyle = 'steps-post' , ** style )
1848
+ ref_axes [5 ].add_line (mlines .Line2D ([0 , y [0 ]], [x [0 ], x [0 ]], ** style ))
1849
+ ref_axes [5 ].add_line (mlines .Line2D ([0 , y [- 1 ]], [x [- 1 ], x [- 1 ]], ** style ))
1849
1850
ref_axes [5 ].semilogx ()
1850
1851
1851
1852
1852
- @check_figures_equal ()
1853
+ @check_figures_equal (extensions = [ 'png' ] )
1853
1854
def test_stairs_fill (fig_test , fig_ref ):
1854
1855
h , bins = [1 , 2 , 3 , 4 , 2 ], [0 , 1 , 2 , 3 , 4 , 5 ]
1855
1856
bs = - 2
1856
1857
# Test
1857
- fig_test , test_axes = plt .subplots (2 , 2 )
1858
- test_axes = test_axes .flatten ()
1858
+ test_axes = fig_test .subplots (2 , 2 ).flatten ()
1859
1859
test_axes [0 ].stairs (h , bins , fill = True )
1860
1860
test_axes [1 ].stairs (h , bins , orientation = 'horizontal' , fill = True )
1861
1861
test_axes [2 ].stairs (h , bins , baseline = bs , fill = True )
1862
1862
test_axes [3 ].stairs (h , bins , baseline = bs , orientation = 'horizontal' ,
1863
- fill = True )
1863
+ fill = True )
1864
1864
1865
1865
# # Ref
1866
- fig_ref , ref_axes = plt .subplots (2 , 2 )
1867
- ref_axes = ref_axes .flatten ()
1868
- ref_axes [0 ].fill_between (bins , np .append (h , h [- 1 ]), step = 'post' )
1866
+ ref_axes = fig_ref .subplots (2 , 2 ).flatten ()
1867
+ ref_axes [0 ].fill_between (bins , np .append (h , h [- 1 ]), step = 'post' , lw = 0 )
1869
1868
ref_axes [0 ].set_ylim (0 , None )
1870
- ref_axes [1 ].fill_betweenx (bins , np .append (h , h [- 1 ]), step = 'post' )
1869
+ ref_axes [1 ].fill_betweenx (bins , np .append (h , h [- 1 ]), step = 'post' , lw = 0 )
1871
1870
ref_axes [1 ].set_xlim (0 , None )
1872
1871
ref_axes [2 ].fill_between (bins , np .append (h , h [- 1 ]),
1873
- np .ones (len (h )+ 1 )* bs , step = 'post' )
1872
+ np .ones (len (h )+ 1 )* bs , step = 'post' , lw = 0 )
1874
1873
ref_axes [2 ].set_ylim (bs , None )
1875
1874
ref_axes [3 ].fill_betweenx (bins , np .append (h , h [- 1 ]),
1876
- np .ones (len (h )+ 1 )* bs , step = 'post' )
1875
+ np .ones (len (h )+ 1 )* bs , step = 'post' , lw = 0 )
1877
1876
ref_axes [3 ].set_xlim (bs , None )
1878
1877
1879
1878
1880
- @check_figures_equal ()
1879
+ @check_figures_equal (extensions = [ 'png' ] )
1881
1880
def test_stairs_update (fig_test , fig_ref ):
1881
+ # fixed ylim because stairs() does autoscale, but updating data does not
1882
+ ylim = - 3 , 4
1882
1883
# Test
1883
- fig_test , test_ax = plt . subplots ()
1884
+ test_ax = fig_test . add_subplot ()
1884
1885
h = test_ax .stairs ([1 , 2 , 3 ])
1886
+ test_ax .set_ylim (ylim )
1885
1887
h .set_values ([3 , 2 , 1 ])
1886
1888
h .set_edges (np .arange (4 )+ 2 )
1887
1889
h .set_data ([1 , 2 , 1 ], np .arange (4 )/ 2 )
@@ -1892,31 +1894,32 @@ def test_stairs_update(fig_test, fig_ref):
1892
1894
h .set_baseline (- 2 )
1893
1895
assert h .get_baseline () == - 2
1894
1896
1895
- # # Ref
1896
- fig_ref , ref_ax = plt . subplots ()
1897
+ # Ref
1898
+ ref_ax = fig_ref . add_subplot ()
1897
1899
h = ref_ax .stairs ([1 , 2 , 3 ], baseline = - 2 )
1900
+ ref_ax .set_ylim (ylim )
1898
1901
1899
1902
1900
- @pytest .mark .xfail
1901
1903
def test_stairs_invalid_nan ():
1902
- plt .stairs ([1 , 2 ], [0 , np .nan , 1 ])
1904
+ with pytest .raises (ValueError , match = 'Nan values in "edges"' ):
1905
+ plt .stairs ([1 , 2 ], [0 , np .nan , 1 ])
1903
1906
1904
1907
1905
- @pytest .mark .xfail
1906
1908
def test_stairs_invalid_mismatch ():
1907
- plt .stairs ([1 , 2 ], [0 , 1 ])
1909
+ with pytest .raises (ValueError , match = 'Size mismatch' ):
1910
+ plt .stairs ([1 , 2 ], [0 , 1 ])
1908
1911
1909
1912
1910
- @pytest .mark .xfail
1911
1913
def test_stairs_invalid_update ():
1912
1914
h = plt .stairs ([1 , 2 ], [0 , 1 , 2 ])
1913
- h .set_edges ([1 , np .nan , 2 ])
1915
+ with pytest .raises (ValueError , match = 'Nan values in "edges"' ):
1916
+ h .set_edges ([1 , np .nan , 2 ])
1914
1917
1915
1918
1916
- @pytest .mark .xfail
1917
1919
def test_stairs_invalid_update2 ():
1918
1920
h = plt .stairs ([1 , 2 ], [0 , 1 , 2 ])
1919
- h .set_edges (np .arange (5 ))
1921
+ with pytest .raises (ValueError , match = 'Size mismatch' ):
1922
+ h .set_edges (np .arange (5 ))
1920
1923
1921
1924
1922
1925
@image_comparison (['test_stairs_options.png' ], remove_text = True )
0 commit comments