diff --git a/doc/source/whatsnew/v0.17.1.txt b/doc/source/whatsnew/v0.17.1.txt index 1eff7d01d9d91..5696d8d7416fc 100755 --- a/doc/source/whatsnew/v0.17.1.txt +++ b/doc/source/whatsnew/v0.17.1.txt @@ -64,7 +64,7 @@ Bug Fixes - +- Bug in ``DataFrame.plot`` cannot use hex strings colors (:issue:`10299`) diff --git a/pandas/tests/test_graphics.py b/pandas/tests/test_graphics.py index b2d8ff8ba0b00..83b76393f30e0 100644 --- a/pandas/tests/test_graphics.py +++ b/pandas/tests/test_graphics.py @@ -2689,6 +2689,18 @@ def test_line_colors(self): self._check_colors(ax.get_lines(), linecolors=['red'] * 5) tm.close() + # GH 10299 + custom_colors = ['#FF0000', '#0000FF', '#FFFF00', '#000000', '#FFFFFF'] + ax = df.plot(color=custom_colors) + self._check_colors(ax.get_lines(), linecolors=custom_colors) + tm.close() + + with tm.assertRaises(ValueError): + # Color contains shorthand hex value results in ValueError + custom_colors = ['#F00', '#00F', '#FF0', '#000', '#FFF'] + # Forced show plot + _check_plot_works(df.plot, color=custom_colors) + @slow def test_line_colors_and_styles_subplots(self): # GH 9894 @@ -2725,6 +2737,20 @@ def test_line_colors_and_styles_subplots(self): self._check_colors(ax.get_lines(), linecolors=[c]) tm.close() + # GH 10299 + custom_colors = ['#FF0000', '#0000FF', '#FFFF00', '#000000', '#FFFFFF'] + axes = df.plot(color=custom_colors, subplots=True) + for ax, c in zip(axes, list(custom_colors)): + self._check_colors(ax.get_lines(), linecolors=[c]) + tm.close() + + with tm.assertRaises(ValueError): + # Color contains shorthand hex value results in ValueError + custom_colors = ['#F00', '#00F', '#FF0', '#000', '#FFF'] + # Forced show plot + _check_plot_works(df.plot, color=custom_colors, subplots=True, + filterwarnings='ignore') + rgba_colors = lmap(cm.jet, np.linspace(0, 1, len(df))) for cmap in ['jet', cm.jet]: axes = df.plot(colormap=cmap, subplots=True)