Repository: pandas-dev/pandas

Issue:
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>



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?



Resolving patch:
diff --git a/pandas/plotting/_core.py b/pandas/plotting/_core.py
--- 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 "


Test patch:
diff --git a/pandas/tests/plotting/test_frame.py b/pandas/tests/plotting/test_frame.py
--- 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):