From 9365d1fd6b5458dd042d5c329e680dc3da7dcbfc Mon Sep 17 00:00:00 2001 From: kjford Date: Fri, 16 Jun 2017 05:46:18 -0700 Subject: [PATCH] BUG: Fix regression for RGB(A) color arguments (#16701) * Add test * Pass tuples that are RGB or RGBA like in list * Update what's new * change whatsnew to reflect regression fix * Add test for RGBA as well (cherry picked from commit 125c414389320dc67ecaffddc65878c01822064e) --- doc/source/whatsnew/v0.20.3.txt | 2 +- pandas/plotting/_core.py | 5 +++++ pandas/tests/plotting/test_frame.py | 6 ++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.20.3.txt b/doc/source/whatsnew/v0.20.3.txt index 249e05623a27f..acd19a8b8da10 100644 --- a/doc/source/whatsnew/v0.20.3.txt +++ b/doc/source/whatsnew/v0.20.3.txt @@ -59,7 +59,7 @@ I/O Plotting ^^^^^^^^ - +- Fix regression in series plotting that prevented RGB and RGBA tuples from being used as color arguments (:issue:`16233`) diff --git a/pandas/plotting/_core.py b/pandas/plotting/_core.py index c66d69d4e324e..ed821bcbbec21 100644 --- a/pandas/plotting/_core.py +++ b/pandas/plotting/_core.py @@ -186,6 +186,11 @@ def _validate_color_args(self): # support series.plot(color='green') self.kwds['color'] = [self.kwds['color']] + if ('color' in self.kwds and isinstance(self.kwds['color'], tuple) and + self.nseries == 1 and len(self.kwds['color']) in (3, 4)): + # support RGB and RGBA tuples in series plot + self.kwds['color'] = [self.kwds['color']] + if ('color' in self.kwds or 'colors' in self.kwds) and \ self.colormap is not None: warnings.warn("'color' and 'colormap' cannot be used " diff --git a/pandas/tests/plotting/test_frame.py b/pandas/tests/plotting/test_frame.py index 7a4aaa3d52b51..7a19418a15004 100644 --- a/pandas/tests/plotting/test_frame.py +++ b/pandas/tests/plotting/test_frame.py @@ -158,6 +158,12 @@ def test_color_single_series_list(self): df = DataFrame({"A": [1, 2, 3]}) _check_plot_works(df.plot, color=['red']) + def test_rgb_tuple_color(self): + # GH 16695 + df = DataFrame({'x': [1, 2], 'y': [3, 4]}) + _check_plot_works(df.plot, x='x', y='y', color=(1, 0, 0)) + _check_plot_works(df.plot, x='x', y='y', color=(1, 0, 0, 0.5)) + def test_color_empty_string(self): df = DataFrame(randn(10, 2)) with pytest.raises(ValueError):