Repository: pandas-dev/pandas

Issue:
VIS: plot method cannot handle new 'C0'-like colors (matplotlib 2.0)
matplotlib 2.0 introduced a few 2-character color abbreviations: C0, C1, C2, ... to refer to the colors of the current color cycle 
(very handy! this way you can refer to a color of the color cycle without hardcoding it, and use it as a shortcut for `color='tab:blue'` if you want the new blue instead of the ugly `color='b'`)

But, it seems pandas cannot handle this at the moment, as it tries to interpret it as multiple colors:

```
df = pd.DataFrame(np.random.randn(10,3), columns=['a', 'b', 'c'])
df.plot(color='C0')
```

gives `ValueError: 'C0' can be parsed as both single color and color cycle. Specify each color using a list like ['C0'] or ['C', '0']`

I know the error message already gives the solution (using `color=['C0']`), but I think it would be nice to special case those to have to working by default.


Discussion:
This one is pretty old, but I'd love to revive it. I'm not sure how tests will cover this change. Is it alright if I give it a try anyway?
sure!

try adding. test with the code as above (u will check this plot works)

Resolving patch:
diff --git a/pandas/tools/plotting.py b/pandas/tools/plotting.py
--- a/pandas/tools/plotting.py
+++ b/pandas/tools/plotting.py
@@ -225,10 +225,18 @@ def _maybe_valid_colors(colors):
         # check whether each character can be convertable to colors
         maybe_color_cycle = _maybe_valid_colors(list(colors))
         if maybe_single_color and maybe_color_cycle and len(colors) > 1:
-            msg = ("'{0}' can be parsed as both single color and "
-                   "color cycle. Specify each color using a list "
-                   "like ['{0}'] or {1}")
-            raise ValueError(msg.format(colors, list(colors)))
+            # Special case for single str 'CN' match and convert to hex
+            # for supporting matplotlib < 2.0.0
+            if re.match(r'\AC[0-9]\Z', colors) and _mpl_ge_2_0_0():
+                hex_color = [c['color']
+                             for c in list(plt.rcParams['axes.prop_cycle'])]
+                colors = [hex_color[int(colors[1])]]
+            else:
+                # this may no longer be required
+                msg = ("'{0}' can be parsed as both single color and "
+                       "color cycle. Specify each color using a list "
+                       "like ['{0}'] or {1}")
+                raise ValueError(msg.format(colors, list(colors)))
         elif maybe_single_color:
             colors = [colors]
         else:
@@ -237,7 +245,10 @@ def _maybe_valid_colors(colors):
             pass
 
     if len(colors) != num_colors:
-        multiple = num_colors // len(colors) - 1
+        try:
+            multiple = num_colors // len(colors) - 1
+        except ZeroDivisionError:
+            raise ValueError("Invalid color argument: ''")
         mod = num_colors % len(colors)
 
         colors += multiple * colors


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
@@ -141,6 +141,22 @@ def test_plot(self):
             result = ax.get_axes()  # deprecated
         self.assertIs(result, axes[0])
 
+    # GH 15516
+    def test_mpl2_color_cycle_str(self):
+        # test CN mpl 2.0 color cycle
+        if self.mpl_ge_2_0_0:
+            colors = ['C' + str(x) for x in range(10)]
+            df = DataFrame(randn(10, 3), columns=['a', 'b', 'c'])
+            for c in colors:
+                _check_plot_works(df.plot, color=c)
+        else:
+            pytest.skip("not supported in matplotlib < 2.0.0")
+
+    def test_color_empty_string(self):
+        df = DataFrame(randn(10, 2))
+        with tm.assertRaises(ValueError):
+            df.plot(color='')
+
     def test_color_and_style_arguments(self):
         df = DataFrame({'x': [1, 2], 'y': [3, 4]})
         # passing both 'color' and 'style' arguments should be allowed