1010import pandas as pd
1111from pandas import (Series , DataFrame , MultiIndex , PeriodIndex , date_range ,
1212 bdate_range )
13+ from pandas .types .api import is_list_like
1314from pandas .compat import (range , lrange , StringIO , lmap , lzip , u , zip , PY3 )
1415from pandas .formats .printing import pprint_thing
1516import pandas .util .testing as tm
@@ -952,9 +953,12 @@ def test_scatter_colors(self):
952953 with tm .assertRaises (TypeError ):
953954 df .plot .scatter (x = 'a' , y = 'b' , c = 'c' , color = 'green' )
954955
956+ default_colors = self ._maybe_unpack_cycler (self .plt .rcParams )
957+
955958 ax = df .plot .scatter (x = 'a' , y = 'b' , c = 'c' )
956- tm .assert_numpy_array_equal (ax .collections [0 ].get_facecolor ()[0 ],
957- np .array ([0 , 0 , 1 , 1 ], dtype = np .float64 ))
959+ tm .assert_numpy_array_equal (
960+ ax .collections [0 ].get_facecolor ()[0 ],
961+ np .array (self .colorconverter .to_rgba (default_colors [0 ])))
958962
959963 ax = df .plot .scatter (x = 'a' , y = 'b' , color = 'white' )
960964 tm .assert_numpy_array_equal (ax .collections [0 ].get_facecolor ()[0 ],
@@ -1623,6 +1627,8 @@ def test_line_colors_and_styles_subplots(self):
16231627
16241628 axes = df .plot (subplots = True )
16251629 for ax , c in zip (axes , list (default_colors )):
1630+ if self .mpl_ge_2_0_0 :
1631+ c = [c ]
16261632 self ._check_colors (ax .get_lines (), linecolors = c )
16271633 tm .close ()
16281634
@@ -1703,9 +1709,14 @@ def test_area_colors(self):
17031709 self ._check_colors (poly , facecolors = custom_colors )
17041710
17051711 handles , labels = ax .get_legend_handles_labels ()
1706- # legend is stored as Line2D, thus check linecolors
1707- linehandles = [x for x in handles if not isinstance (x , PolyCollection )]
1708- self ._check_colors (linehandles , linecolors = custom_colors )
1712+ if self .mpl_ge_1_5_0 :
1713+ self ._check_colors (handles , facecolors = custom_colors )
1714+ else :
1715+ # legend is stored as Line2D, thus check linecolors
1716+ linehandles = [x for x in handles
1717+ if not isinstance (x , PolyCollection )]
1718+ self ._check_colors (linehandles , linecolors = custom_colors )
1719+
17091720 for h in handles :
17101721 self .assertTrue (h .get_alpha () is None )
17111722 tm .close ()
@@ -1717,8 +1728,12 @@ def test_area_colors(self):
17171728 self ._check_colors (poly , facecolors = jet_colors )
17181729
17191730 handles , labels = ax .get_legend_handles_labels ()
1720- linehandles = [x for x in handles if not isinstance (x , PolyCollection )]
1721- self ._check_colors (linehandles , linecolors = jet_colors )
1731+ if self .mpl_ge_1_5_0 :
1732+ self ._check_colors (handles , facecolors = jet_colors )
1733+ else :
1734+ linehandles = [x for x in handles
1735+ if not isinstance (x , PolyCollection )]
1736+ self ._check_colors (linehandles , linecolors = jet_colors )
17221737 for h in handles :
17231738 self .assertTrue (h .get_alpha () is None )
17241739 tm .close ()
@@ -1731,8 +1746,12 @@ def test_area_colors(self):
17311746 self ._check_colors (poly , facecolors = jet_with_alpha )
17321747
17331748 handles , labels = ax .get_legend_handles_labels ()
1734- # Line2D can't have alpha in its linecolor
1735- self ._check_colors (handles [:len (jet_colors )], linecolors = jet_colors )
1749+ if self .mpl_ge_1_5_0 :
1750+ linecolors = jet_with_alpha
1751+ else :
1752+ # Line2D can't have alpha in its linecolor
1753+ linecolors = jet_colors
1754+ self ._check_colors (handles [:len (jet_colors )], linecolors = linecolors )
17361755 for h in handles :
17371756 self .assertEqual (h .get_alpha (), 0.5 )
17381757
@@ -1855,7 +1874,10 @@ def test_kde_colors_and_styles_subplots(self):
18551874 @slow
18561875 def test_boxplot_colors (self ):
18571876 def _check_colors (bp , box_c , whiskers_c , medians_c , caps_c = 'k' ,
1858- fliers_c = 'b' ):
1877+ fliers_c = None ):
1878+ # TODO: outside this func?
1879+ if fliers_c is None :
1880+ fliers_c = 'k' if self .mpl_ge_2_0_0 else 'b'
18591881 self ._check_colors (bp ['boxes' ],
18601882 linecolors = [box_c ] * len (bp ['boxes' ]))
18611883 self ._check_colors (bp ['whiskers' ],
@@ -2232,16 +2254,24 @@ def test_errorbar_asymmetrical(self):
22322254 np .random .seed (0 )
22332255 err = np .random .rand (3 , 2 , 5 )
22342256
2235- data = np .random .randn (5 , 3 )
2236- df = DataFrame (data )
2257+ # each column is [0, 1, 2, 3, 4], [3, 4, 5, 6, 7]...
2258+ df = DataFrame (np .arange (15 ).reshape (3 , 5 )).T
2259+ data = df .values
22372260
22382261 ax = df .plot (yerr = err , xerr = err / 2 )
22392262
2240- self .assertEqual (ax .lines [7 ].get_ydata ()[0 ], data [0 , 1 ] - err [1 , 0 , 0 ])
2241- self .assertEqual (ax .lines [8 ].get_ydata ()[0 ], data [0 , 1 ] + err [1 , 1 , 0 ])
2263+ if self .mpl_ge_2_0_0 :
2264+ yerr_0_0 = ax .collections [1 ].get_paths ()[0 ].vertices [:, 1 ]
2265+ expected_0_0 = err [0 , :, 0 ] * np .array ([- 1 , 1 ])
2266+ tm .assert_almost_equal (yerr_0_0 , expected_0_0 )
2267+ else :
2268+ self .assertEqual (ax .lines [7 ].get_ydata ()[0 ],
2269+ data [0 , 1 ] - err [1 , 0 , 0 ])
2270+ self .assertEqual (ax .lines [8 ].get_ydata ()[0 ],
2271+ data [0 , 1 ] + err [1 , 1 , 0 ])
22422272
2243- self .assertEqual (ax .lines [5 ].get_xdata ()[0 ], - err [1 , 0 , 0 ] / 2 )
2244- self .assertEqual (ax .lines [6 ].get_xdata ()[0 ], err [1 , 1 , 0 ] / 2 )
2273+ self .assertEqual (ax .lines [5 ].get_xdata ()[0 ], - err [1 , 0 , 0 ] / 2 )
2274+ self .assertEqual (ax .lines [6 ].get_xdata ()[0 ], err [1 , 1 , 0 ] / 2 )
22452275
22462276 with tm .assertRaises (ValueError ):
22472277 df .plot (yerr = err .T )
@@ -2277,9 +2307,17 @@ def test_errorbar_scatter(self):
22772307 self ._check_has_errorbars (ax , xerr = 1 , yerr = 1 )
22782308
22792309 def _check_errorbar_color (containers , expected , has_err = 'has_xerr' ):
2280- errs = [c .lines [1 ][0 ]
2281- for c in ax .containers if getattr (c , has_err , False )]
2282- self ._check_colors (errs , linecolors = [expected ] * len (errs ))
2310+ lines = []
2311+ errs = [c .lines
2312+ for c in ax .containers if getattr (c , has_err , False )][0 ]
2313+ for el in errs :
2314+ if is_list_like (el ):
2315+ lines .extend (el )
2316+ else :
2317+ lines .append (el )
2318+ err_lines = [x for x in lines if x in ax .collections ]
2319+ self ._check_colors (
2320+ err_lines , linecolors = np .array ([expected ] * len (err_lines )))
22832321
22842322 # GH 8081
22852323 df = DataFrame (
0 commit comments