Repository: pandas-dev/pandas
Pull request: BUG: Fix regression for RGB(A) color arguments
 - [ ] closes #16695
 - [x] test added / passed
 - [x] passes ``git diff upstream/master --name-only -- '*.py' | flake8 --diff``
 - [x] whatsnew entry

Fixes a regression in the plot API in which RGB and RGBA tuples in the `color` kwarg caused an error when passed to matplotlib.  The root cause of this error is the fact that anything list-like passed with the `color` kwarg is treated as a set of colors to be mapped to the series being plotted.

This PR specifically fixes issues where a series is being plotted using an RGB(A) tuple to specify color.

This fixes only the regression between previous versions and 0.20.2.  There are still API inconsistencies with color specification using RGB(A) tuples versus other methods, e.g.  
```python
df = pandas.DataFrame({'a': [1, 2], 'b': [3, 4]})
df.plot(color=(1, 0, 0))  # will still fail since there are 2 columns to plot
df.plot(color='r')  # works
```



Problem statement:
DataFrame plot method no long takes RGB tuple as color arg
#### Problem description

The `plot` method on `DataFrame` objects takes a `color` argument that in versions prior to 0.20.2 took an RGB tuple as an accepted value.  The 0.20.2 release throws an exception when specifying an RGB tuple for the `color` arg.

#### Code Sample

```python
# import matplotlib.pyplot as plt
df = pandas.DataFrame([[1, 2], [3, 4]], columns=['a', 'b'])
df.plot(x='b', y='a', color=(1, 0, 0))
plt.show()
```


#### Expected Output

The expected output is a red line plot.  The following exception is thrown:

```python
Exception in Tkinter callback
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py", line 1536, in __call__
    return self.func(*args)
  File "/venvs/pandas0.20.2/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.py", line 280, in resize
    self.show()
  File "/venvs/pandas0.20.2/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.py", line 351, in draw
    FigureCanvasAgg.draw(self)
  File "/venvs/pandas0.20.2/lib/python2.7/site-packages/matplotlib/backends/backend_agg.py", line 464, in draw
    self.figure.draw(self.renderer)
  File "/venvs/pandas0.20.2/lib/python2.7/site-packages/matplotlib/artist.py", line 63, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/venvs/pandas0.20.2/lib/python2.7/site-packages/matplotlib/figure.py", line 1144, in draw
    renderer, self, dsu, self.suppressComposite)
  File "/venvs/pandas0.20.2/lib/python2.7/site-packages/matplotlib/image.py", line 139, in _draw_list_compositing_images
    a.draw(renderer)
  File "/venvs/pandas0.20.2/lib/python2.7/site-packages/matplotlib/artist.py", line 63, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/venvs/pandas0.20.2/lib/python2.7/site-packages/matplotlib/axes/_base.py", line 2426, in draw
    mimage._draw_list_compositing_images(renderer, self, dsu)
  File "/venvs/pandas0.20.2/lib/python2.7/site-packages/matplotlib/image.py", line 139, in _draw_list_compositing_images
    a.draw(renderer)
  File "/venvs/pandas0.20.2/lib/python2.7/site-packages/matplotlib/artist.py", line 63, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/venvs/pandas0.20.2/lib/python2.7/site-packages/matplotlib/lines.py", line 803, in draw
    ln_color_rgba = self._get_rgba_ln_color()
  File "/venvs/pandas0.20.2/lib/python2.7/site-packages/matplotlib/lines.py", line 1344, in _get_rgba_ln_color
    return mcolors.to_rgba(self._color, self._alpha)
  File "/venvs/pandas0.20.2/lib/python2.7/site-packages/matplotlib/colors.py", line 143, in to_rgba
    rgba = _to_rgba_no_colorcycle(c, alpha)
  File "/venvs/pandas0.20.2/lib/python2.7/site-packages/matplotlib/colors.py", line 194, in _to_rgba_no_colorcycle
    raise ValueError("Invalid RGBA argument: {!r}".format(orig_c))
ValueError: Invalid RGBA argument: 1
```

This plot is correctly displayed with an identical environment that has pandas 0.19.2 installed so is API breaking.  

Apologies if this is fixed already in master.

#### Output of ``pd.show_versions()``

<details>
NSTALLED VERSIONS
------------------
commit: None
python: 2.7.10.final.0
python-bits: 64
OS: Darwin
OS-release: 15.2.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8

pandas: 0.20.2
pytest: None
pip: 9.0.1
setuptools: 36.0.1
Cython: None
numpy: 1.13.0
scipy: None
xarray: None
IPython: 5.4.1
sphinx: None
patsy: None
dateutil: 2.6.0
pytz: 2017.2
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 2.0.2
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: None
s3fs: None
pandas_gbq: None
pandas_datareader: None

</details>

Hints from issue discussion:
Follow up:
Enclosing the tuple in a list works:
```
df.plot(x='b', y='a', color=[(1, 0, 0)])
```
This looks related to #16233 which fixes #3486 but breaks what I perceive to be a fairly standard way of assigning line color (e.g. it is the first method listed for specifying color on https://matplotlib.org/users/colors.html).
@kjford Thanks for the report! That is indeed a regression, and should be fixed. 

Want to do a PR to fix?

Commit message: Update what's new

Patch to review:
diff --git a/doc/source/whatsnew/v0.20.3.txt b/doc/source/whatsnew/v0.20.3.txt
index 249e05623a27f..87ecedda8eec6 100644
--- a/doc/source/whatsnew/v0.20.3.txt
+++ b/doc/source/whatsnew/v0.20.3.txt
@@ -59,7 +59,7 @@ I/O
 
 Plotting
 ^^^^^^^^
-
+- Allow series plots to accept RGB and RGBA tuples as color arguments (:issue:`16233`)
 
 
 
diff --git a/pandas/plotting/_core.py b/pandas/plotting/_core.py
index 391fa377f3c6f..f8e83aea03594 100644
--- a/pandas/plotting/_core.py
+++ b/pandas/plotting/_core.py
@@ -187,6 +187,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 ba674e10be384..01f7bc94567a0 100644
--- a/pandas/tests/plotting/test_frame.py
+++ b/pandas/tests/plotting/test_frame.py
@@ -158,6 +158,11 @@ 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))
+
     def test_color_empty_string(self):
         df = DataFrame(randn(10, 2))
         with pytest.raises(ValueError):


Code review comments:
diff_hunk: @@ -59,7 +59,7 @@ I/O
 
 Plotting
 ^^^^^^^^
-
+- Allow series plots to accept RGB and RGBA tuples as color arguments (:issue:`16233`)
path: doc/source/whatsnew/v0.20.3.txt
text: @user1:
I would that the sentence with "Fix bug" or "Fix regression in ..", as it now sounds that this a new thing that it is allowed.