diff --git a/doc/source/whatsnew/v1.0.0.rst b/doc/source/whatsnew/v1.0.0.rst index b40a64420a0be..29a562aa1a1f2 100644 --- a/doc/source/whatsnew/v1.0.0.rst +++ b/doc/source/whatsnew/v1.0.0.rst @@ -410,6 +410,7 @@ Plotting - Bug in the ``xticks`` argument being ignored for :meth:`DataFrame.plot.bar` (:issue:`14119`) - :func:`set_option` now validates that the plot backend provided to ``'plotting.backend'`` implements the backend when the option is set, rather than when a plot is created (:issue:`28163`) - :meth:`DataFrame.plot` now allow a ``backend`` keyword arugment to allow changing between backends in one session (:issue:`28619`). +- Bug in color validation incorrectly raising for non-color styles (:issue:`29122`). Groupby/resample/rolling ^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/pandas/plotting/_matplotlib/core.py b/pandas/plotting/_matplotlib/core.py index 541dca715e814..5853367f71d56 100644 --- a/pandas/plotting/_matplotlib/core.py +++ b/pandas/plotting/_matplotlib/core.py @@ -193,6 +193,8 @@ def __init__( self._validate_color_args() def _validate_color_args(self): + import matplotlib.colors + if "color" not in self.kwds and "colors" in self.kwds: warnings.warn( ( @@ -234,13 +236,14 @@ def _validate_color_args(self): styles = [self.style] # need only a single match for s in styles: - if re.match("^[a-z]+?", s) is not None: - raise ValueError( - "Cannot pass 'style' string with a color " - "symbol and 'color' keyword argument. Please" - " use one or the other or pass 'style' " - "without a color symbol" - ) + for char in s: + if char in matplotlib.colors.BASE_COLORS: + raise ValueError( + "Cannot pass 'style' string with a color " + "symbol and 'color' keyword argument. Please" + " use one or the other or pass 'style' " + "without a color symbol" + ) def _iter_data(self, data=None, keep_index=False, fillna=None): if data is None: diff --git a/pandas/tests/plotting/test_series.py b/pandas/tests/plotting/test_series.py index 89259cbb6c62d..766b1f61e9c1b 100644 --- a/pandas/tests/plotting/test_series.py +++ b/pandas/tests/plotting/test_series.py @@ -931,3 +931,8 @@ def test_plot_no_numeric_data(self): df = pd.Series(["a", "b", "c"]) with pytest.raises(TypeError): df.plot() + + def test_style_single_ok(self): + s = pd.Series([1, 2]) + ax = s.plot(style="s", color="C3") + assert ax.lines[0].get_color() == ["C3"]