diff --git a/pandas/tests/test_graphics.py b/pandas/tests/test_graphics.py index f2fd98169b585..efb3252a66209 100644 --- a/pandas/tests/test_graphics.py +++ b/pandas/tests/test_graphics.py @@ -489,6 +489,16 @@ def test_series_plot_color_kwargs(self): line = ax.get_lines()[0] self.assert_(line.get_color() == 'green') + @slow + def test_time_series_plot_color_kwargs(self): + # #1890 + import matplotlib.pyplot as plt + + plt.close('all') + ax = Series(np.arange(12) + 1, index=date_range('1/1/2000', periods=12)).plot(color='green') + line = ax.get_lines()[0] + self.assert_(line.get_color() == 'green') + PNG_PATH = 'tmp.png' def _check_plot_works(f, *args, **kwargs): diff --git a/pandas/tools/plotting.py b/pandas/tools/plotting.py index 60ed0c70d516b..aa6c23e10c2c6 100644 --- a/pandas/tools/plotting.py +++ b/pandas/tools/plotting.py @@ -876,6 +876,12 @@ def _get_colors(self): colors = self.kwds.pop('colors', cycle) return has_colors, colors + def _maybe_add_color(self, has_colors, colors, kwds, style, i): + if (not has_colors and + (style is None or re.match('[a-z]+', style) is None) + and 'color' not in kwds): + kwds['color'] = colors[i % len(colors)] + def _make_plot(self): # this is slightly deceptive if self.use_index and self._use_dynamic_x(): @@ -886,21 +892,14 @@ def _make_plot(self): labels = [] x = self._get_xticks(convert_period=True) - has_colors, colors = self._get_colors() - def _maybe_add_color(kwargs, style, i): - if (not has_colors and - (style is None or re.match('[a-z]+', style) is None) - and 'color' not in kwargs): - kwargs['color'] = colors[i % len(colors)] - plotf = self._get_plot_function() + has_colors, colors = self._get_colors() for i, (label, y) in enumerate(self._iter_data()): ax = self._get_ax(i) style = self._get_style(i, label) kwds = self.kwds.copy() - - _maybe_add_color(kwds, style, i) + self._maybe_add_color(has_colors, colors, kwds, style, i) label = _stringify(label) @@ -934,11 +933,6 @@ def _make_ts_plot(self, data, **kwargs): lines = [] labels = [] - def _maybe_add_color(kwargs, style, i): - if (not has_colors and - (style is None or re.match('[a-z]+', style) is None)): - kwargs['color'] = colors[i % len(colors)] - def to_leg_label(label, i): if self.mark_right and self.on_right(i): return label + ' (right)' @@ -949,7 +943,7 @@ def to_leg_label(label, i): style = self.style or '' label = com._stringify(self.label) kwds = kwargs.copy() - _maybe_add_color(kwds, style, 0) + self._maybe_add_color(has_colors, colors, kwds, style, 0) newlines = tsplot(data, plotf, ax=ax, label=label, style=self.style, **kwds) @@ -964,7 +958,7 @@ def to_leg_label(label, i): style = self._get_style(i, col) kwds = kwargs.copy() - _maybe_add_color(kwds, style, i) + self._maybe_add_color(has_colors, colors, kwds, style, i) newlines = tsplot(data[col], plotf, ax=ax, label=label, style=style, **kwds)