@@ -1676,63 +1676,120 @@ def test_hist2d_transpose():
1676
1676
ax .hist2d (x ,y ,bins = 10 ,rasterized = True )
1677
1677
1678
1678
1679
- @image_comparison (baseline_images = ['scatter' ,'scatter' ])
1680
- def test_scatter_plot ():
1681
- fig ,ax = plt .subplots ()
1682
- data = {"x" : [3 ,4 ,2 ,6 ],"y" : [2 ,5 ,2 ,3 ],"c" : ['r' ,'y' ,'b' ,'lime' ],
1683
- "s" : [24 ,15 ,19 ,29 ]}
1684
-
1685
- ax .scatter (data ["x" ],data ["y" ],c = data ["c" ],s = data ["s" ])
1686
-
1687
- # Reuse testcase from above for a labeled data test
1688
- fig ,ax = plt .subplots ()
1689
- ax .scatter ("x" ,"y" ,c = "c" ,s = "s" ,data = data )
1679
+ class TestScatter (object ):
1680
+ @image_comparison (baseline_images = ['scatter' ,'scatter' ])
1681
+ def test_scatter_plot (self ):
1682
+ fig ,ax = plt .subplots ()
1683
+ data = {"x" : [3 ,4 ,2 ,6 ],"y" : [2 ,5 ,2 ,3 ],
1684
+ "c" : ['r' ,'y' ,'b' ,'lime' ],"s" : [24 ,15 ,19 ,29 ]}
1690
1685
1686
+ ax .scatter (data ["x" ],data ["y" ],c = data ["c" ],s = data ["s" ])
1691
1687
1692
- @image_comparison (baseline_images = ['scatter_marker' ],remove_text = True ,
1693
- extensions = ['png' ])
1694
- def test_scatter_marker ():
1695
- fig , (ax0 ,ax1 ,ax2 )= plt .subplots (ncols = 3 )
1696
- ax0 .scatter ([3 ,4 ,2 ,6 ], [2 ,5 ,2 ,3 ],
1697
- c = [(1 ,0 ,0 ),'y' ,'b' ,'lime' ],
1698
- s = [60 ,50 ,40 ,30 ],
1699
- edgecolors = ['k' ,'r' ,'g' ,'b' ],
1700
- marker = 's' )
1701
- ax1 .scatter ([3 ,4 ,2 ,6 ], [2 ,5 ,2 ,3 ],
1702
- c = [(1 ,0 ,0 ),'y' ,'b' ,'lime' ],
1703
- s = [60 ,50 ,40 ,30 ],
1704
- edgecolors = ['k' ,'r' ,'g' ,'b' ],
1705
- marker = mmarkers .MarkerStyle ('o' ,fillstyle = 'top' ))
1706
- # unit area ellipse
1707
- rx ,ry = 3 ,1
1708
- area = rx * ry * np .pi
1709
- theta = np .linspace (0 ,2 * np .pi ,21 )
1710
- verts = np .column_stack ([np .cos (theta )* rx / area ,
1711
- np .sin (theta )* ry / area ])
1712
- ax2 .scatter ([3 ,4 ,2 ,6 ], [2 ,5 ,2 ,3 ],
1713
- c = [(1 ,0 ,0 ),'y' ,'b' ,'lime' ],
1714
- s = [60 ,50 ,40 ,30 ],
1715
- edgecolors = ['k' ,'r' ,'g' ,'b' ],
1716
- marker = verts )
1717
-
1718
-
1719
- @image_comparison (baseline_images = ['scatter_2D' ],remove_text = True ,
1720
- extensions = ['png' ])
1721
- def test_scatter_2D ():
1722
- x = np .arange (3 )
1723
- y = np .arange (2 )
1724
- x ,y = np .meshgrid (x ,y )
1725
- z = x + y
1726
- fig ,ax = plt .subplots ()
1727
- ax .scatter (x ,y ,c = z ,s = 200 ,edgecolors = 'face' )
1688
+ # Reuse testcase from above for a labeled data test
1689
+ fig ,ax = plt .subplots ()
1690
+ ax .scatter ("x" ,"y" ,c = "c" ,s = "s" ,data = data )
1691
+
1692
+ @image_comparison (baseline_images = ['scatter_marker' ],remove_text = True ,
1693
+ extensions = ['png' ])
1694
+ def test_scatter_marker (self ):
1695
+ fig , (ax0 ,ax1 ,ax2 )= plt .subplots (ncols = 3 )
1696
+ ax0 .scatter ([3 ,4 ,2 ,6 ], [2 ,5 ,2 ,3 ],
1697
+ c = [(1 ,0 ,0 ),'y' ,'b' ,'lime' ],
1698
+ s = [60 ,50 ,40 ,30 ],
1699
+ edgecolors = ['k' ,'r' ,'g' ,'b' ],
1700
+ marker = 's' )
1701
+ ax1 .scatter ([3 ,4 ,2 ,6 ], [2 ,5 ,2 ,3 ],
1702
+ c = [(1 ,0 ,0 ),'y' ,'b' ,'lime' ],
1703
+ s = [60 ,50 ,40 ,30 ],
1704
+ edgecolors = ['k' ,'r' ,'g' ,'b' ],
1705
+ marker = mmarkers .MarkerStyle ('o' ,fillstyle = 'top' ))
1706
+ # unit area ellipse
1707
+ rx ,ry = 3 ,1
1708
+ area = rx * ry * np .pi
1709
+ theta = np .linspace (0 ,2 * np .pi ,21 )
1710
+ verts = np .column_stack ([np .cos (theta )* rx / area ,
1711
+ np .sin (theta )* ry / area ])
1712
+ ax2 .scatter ([3 ,4 ,2 ,6 ], [2 ,5 ,2 ,3 ],
1713
+ c = [(1 ,0 ,0 ),'y' ,'b' ,'lime' ],
1714
+ s = [60 ,50 ,40 ,30 ],
1715
+ edgecolors = ['k' ,'r' ,'g' ,'b' ],
1716
+ verts = verts )
1717
+
1718
+ @image_comparison (baseline_images = ['scatter_2D' ],remove_text = True ,
1719
+ extensions = ['png' ])
1720
+ def test_scatter_2D (self ):
1721
+ x = np .arange (3 )
1722
+ y = np .arange (2 )
1723
+ x ,y = np .meshgrid (x ,y )
1724
+ z = x + y
1725
+ fig ,ax = plt .subplots ()
1726
+ ax .scatter (x ,y ,c = z ,s = 200 ,edgecolors = 'face' )
1727
+
1728
+ def test_scatter_color (self ):
1729
+ # Try to catch cases where 'c' kwarg should have been used.
1730
+ with pytest .raises (ValueError ):
1731
+ plt .scatter ([1 ,2 ], [1 ,2 ],color = [0.1 ,0.2 ])
1732
+ with pytest .raises (ValueError ):
1733
+ plt .scatter ([1 ,2 ,3 ], [1 ,2 ,3 ],color = [1 ,2 ,3 ])
1734
+
1735
+ # Parameters for *test_scatter_c*. NB: assuming that the
1736
+ # scatter plot will have 4 elements. The tuple scheme is:
1737
+ # (*c* parameter case, exception regexp key or None if no exception)
1738
+ params_test_scatter_c = [
1739
+ # Single letter-sequences
1740
+ ("rgby" ,None ),
1741
+ ("rgb" ,"shape" ),
1742
+ ("rgbrgb" ,"shape" ),
1743
+ (["rgby" ],"conversion" ),
1744
+ # Special cases
1745
+ ("red" ,None ),
1746
+ ("none" ,None ),
1747
+ (None ,None ),
1748
+ (["r" ,"g" ,"b" ,"none" ],None ),
1749
+ # Non-valid color spec (FWIW, 'jaune' means yellow in French)
1750
+ ("jaune" ,"conversion" ),
1751
+ (["jaune" ],"conversion" ),# wrong type before wrong size
1752
+ (["jaune" ]* 4 ,"conversion" ),
1753
+ # Value-mapping like
1754
+ ([0.5 ]* 3 ,None ),# should emit a warning for user's eyes though
1755
+ ([0.5 ]* 4 ,None ),# NB: no warning as matching size allows mapping
1756
+ ([0.5 ]* 5 ,"shape" ),
1757
+ # RGB values
1758
+ ([[1 ,0 ,0 ]],None ),
1759
+ ([[1 ,0 ,0 ]]* 3 ,"shape" ),
1760
+ ([[1 ,0 ,0 ]]* 4 ,None ),
1761
+ ([[1 ,0 ,0 ]]* 5 ,"shape" ),
1762
+ # RGBA values
1763
+ ([[1 ,0 ,0 ,0.5 ]],None ),
1764
+ ([[1 ,0 ,0 ,0.5 ]]* 3 ,"shape" ),
1765
+ ([[1 ,0 ,0 ,0.5 ]]* 4 ,None ),
1766
+ ([[1 ,0 ,0 ,0.5 ]]* 5 ,"shape" ),
1767
+ # Mix of valid color specs
1768
+ ([[1 ,0 ,0 ,0.5 ]]* 3 + [[1 ,0 ,0 ]],None ),
1769
+ ([[1 ,0 ,0 ,0.5 ],"red" ,"0.0" ],"shape" ),
1770
+ ([[1 ,0 ,0 ,0.5 ],"red" ,"0.0" ,"C5" ],None ),
1771
+ ([[1 ,0 ,0 ,0.5 ],"red" ,"0.0" ,"C5" , [0 ,1 ,0 ]],"shape" ),
1772
+ # Mix of valid and non valid color specs
1773
+ ([[1 ,0 ,0 ,0.5 ],"red" ,"jaune" ],"conversion" ),
1774
+ ([[1 ,0 ,0 ,0.5 ],"red" ,"0.0" ,"jaune" ],"conversion" ),
1775
+ ([[1 ,0 ,0 ,0.5 ],"red" ,"0.0" ,"C5" ,"jaune" ],"conversion" ),
1776
+ ]
1728
1777
1778
+ @pytest .mark .parametrize ('c_case, re_key' ,params_test_scatter_c )
1779
+ def test_scatter_c (self ,c_case ,re_key ):
1780
+ # Additional checking of *c* (introduced in #11383).
1781
+ REGEXP = {
1782
+ "shape" :"^'c' argument has [0-9]+ elements" ,# shape mismatch
1783
+ "conversion" :"^'c' argument must either be valid" ,# bad vals
1784
+ }
1785
+ x = y = [0 ,1 ,2 ,3 ]
1786
+ fig ,ax = plt .subplots ()
1729
1787
1730
- def test_scatter_color ():
1731
- # Try to catch cases where 'c' kwarg should have been used.
1732
- with pytest .raises (ValueError ):
1733
- plt .scatter ([1 ,2 ], [1 ,2 ],color = [0.1 ,0.2 ])
1734
- with pytest .raises (ValueError ):
1735
- plt .scatter ([1 ,2 ,3 ], [1 ,2 ,3 ],color = [1 ,2 ,3 ])
1788
+ if re_key is None :
1789
+ ax .scatter (x ,y ,c = c_case ,edgecolors = "black" )
1790
+ else :
1791
+ with pytest .raises (ValueError ,match = REGEXP [re_key ]):
1792
+ ax .scatter (x ,y ,c = c_case ,edgecolors = "black" )
1736
1793
1737
1794
1738
1795
def test_as_mpl_axes_api ():