10
10
import pandas as pd
11
11
from pandas import (Series , DataFrame , MultiIndex , PeriodIndex , date_range ,
12
12
bdate_range )
13
+ from pandas .types .api import is_list_like
13
14
from pandas .compat import (range , lrange , StringIO , lmap , lzip , u , zip , PY3 )
14
15
from pandas .formats .printing import pprint_thing
15
16
import pandas .util .testing as tm
@@ -952,9 +953,12 @@ def test_scatter_colors(self):
952
953
with tm .assertRaises (TypeError ):
953
954
df .plot .scatter (x = 'a' , y = 'b' , c = 'c' , color = 'green' )
954
955
956
+ default_colors = self ._maybe_unpack_cycler (self .plt .rcParams )
957
+
955
958
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 ])))
958
962
959
963
ax = df .plot .scatter (x = 'a' , y = 'b' , color = 'white' )
960
964
tm .assert_numpy_array_equal (ax .collections [0 ].get_facecolor ()[0 ],
@@ -1623,6 +1627,8 @@ def test_line_colors_and_styles_subplots(self):
1623
1627
1624
1628
axes = df .plot (subplots = True )
1625
1629
for ax , c in zip (axes , list (default_colors )):
1630
+ if self .mpl_ge_2_0_0 :
1631
+ c = [c ]
1626
1632
self ._check_colors (ax .get_lines (), linecolors = c )
1627
1633
tm .close ()
1628
1634
@@ -1703,9 +1709,14 @@ def test_area_colors(self):
1703
1709
self ._check_colors (poly , facecolors = custom_colors )
1704
1710
1705
1711
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
+
1709
1720
for h in handles :
1710
1721
self .assertTrue (h .get_alpha () is None )
1711
1722
tm .close ()
@@ -1717,8 +1728,12 @@ def test_area_colors(self):
1717
1728
self ._check_colors (poly , facecolors = jet_colors )
1718
1729
1719
1730
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 )
1722
1737
for h in handles :
1723
1738
self .assertTrue (h .get_alpha () is None )
1724
1739
tm .close ()
@@ -1731,8 +1746,12 @@ def test_area_colors(self):
1731
1746
self ._check_colors (poly , facecolors = jet_with_alpha )
1732
1747
1733
1748
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 )
1736
1755
for h in handles :
1737
1756
self .assertEqual (h .get_alpha (), 0.5 )
1738
1757
@@ -1855,7 +1874,10 @@ def test_kde_colors_and_styles_subplots(self):
1855
1874
@slow
1856
1875
def test_boxplot_colors (self ):
1857
1876
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'
1859
1881
self ._check_colors (bp ['boxes' ],
1860
1882
linecolors = [box_c ] * len (bp ['boxes' ]))
1861
1883
self ._check_colors (bp ['whiskers' ],
@@ -2232,16 +2254,24 @@ def test_errorbar_asymmetrical(self):
2232
2254
np .random .seed (0 )
2233
2255
err = np .random .rand (3 , 2 , 5 )
2234
2256
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
2237
2260
2238
2261
ax = df .plot (yerr = err , xerr = err / 2 )
2239
2262
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 ])
2242
2272
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 )
2245
2275
2246
2276
with tm .assertRaises (ValueError ):
2247
2277
df .plot (yerr = err .T )
@@ -2277,9 +2307,17 @@ def test_errorbar_scatter(self):
2277
2307
self ._check_has_errorbars (ax , xerr = 1 , yerr = 1 )
2278
2308
2279
2309
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 )))
2283
2321
2284
2322
# GH 8081
2285
2323
df = DataFrame (
0 commit comments