From 2b7bcee357a7b54c801b5178048632bb65219143 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Est=C3=A8ve?= Date: Sun, 10 Feb 2013 23:27:33 +0000 Subject: [PATCH 1/3] BUG: automatic color cycling when plotting Series without style or color argument --- pandas/tests/test_graphics.py | 12 ++++++++++++ pandas/tools/plotting.py | 5 ++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/pandas/tests/test_graphics.py b/pandas/tests/test_graphics.py index b264e8696ec4b..2a8a772c1db93 100644 --- a/pandas/tests/test_graphics.py +++ b/pandas/tests/test_graphics.py @@ -678,6 +678,18 @@ def test_time_series_plot_color_kwargs(self): line = ax.get_lines()[0] self.assert_(line.get_color() == 'green') + @slow + def test_time_series_plot_color_with_empty_kwargs(self): + import matplotlib.pyplot as plt + + plt.close('all') + for i in range(3): + ax = Series(np.arange(12) + 1, index=date_range( + '1/1/2000', periods=12)).plot() + + line_colors = [ l.get_color() for l in ax.get_lines() ] + self.assert_(line_colors == ['b', 'g', 'r']) + @slow def test_grouped_hist(self): import matplotlib.pyplot as plt diff --git a/pandas/tools/plotting.py b/pandas/tools/plotting.py index 137eab65620c6..f931c4fadbb7c 100644 --- a/pandas/tools/plotting.py +++ b/pandas/tools/plotting.py @@ -1122,13 +1122,12 @@ def _get_colors(self): cycle = plt.rcParams.get('axes.color_cycle', list('bgrcmyk')) if isinstance(cycle, basestring): cycle = list(cycle) - has_colors = 'color' in self.kwds colors = self.kwds.get('color', cycle) return colors def _maybe_add_color(self, colors, kwds, style, i): - kwds.pop('color', None) - if style is None or re.match('[a-z]+', style) is None: + has_color = 'color' in kwds + if has_color and (style is None or re.match('[a-z]+', style) is None): kwds['color'] = colors[i % len(colors)] def _make_plot(self): From 5b16e78c526ed766af5c661b955ae8be19835e5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Est=C3=A8ve?= Date: Tue, 26 Mar 2013 00:29:39 +0000 Subject: [PATCH 2/3] Share color cycle between left and right axes --- pandas/tools/plotting.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pandas/tools/plotting.py b/pandas/tools/plotting.py index f931c4fadbb7c..2b471cbf13192 100644 --- a/pandas/tools/plotting.py +++ b/pandas/tools/plotting.py @@ -807,6 +807,8 @@ def _maybe_right_yaxis(self, ax): if (sec_true or has_sec) and not hasattr(ax, 'right_ax'): orig_ax, new_ax = ax, ax.twinx() + new_ax._get_lines.color_cycle = orig_ax._get_lines.color_cycle + orig_ax.right_ax, new_ax.left_ax = new_ax, orig_ax if len(orig_ax.get_lines()) == 0: # no data on left y @@ -2146,6 +2148,8 @@ def on_right(i): if on_right(0): orig_ax = ax0 ax0 = ax0.twinx() + ax0._get_lines.color_cycle = orig_ax._get_lines.color_cycle + orig_ax.get_yaxis().set_visible(False) orig_ax.right_ax = ax0 ax0.left_ax = orig_ax @@ -2163,6 +2167,8 @@ def on_right(i): if on_right(i): orig_ax = ax ax = ax.twinx() + ax._get_lines.color_cycle = orig_ax._get_lines.color_cycle + orig_ax.get_yaxis().set_visible(False) axarr[i] = ax From 2dd5f7b0bf9fb04aee689071083d41afa7d5253f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Est=C3=A8ve?= Date: Thu, 28 Mar 2013 19:00:54 +0000 Subject: [PATCH 3/3] Add note in RELEASE.rst --- RELEASE.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/RELEASE.rst b/RELEASE.rst index 7a8e8d583f8e3..d26b599de05b1 100644 --- a/RELEASE.rst +++ b/RELEASE.rst @@ -246,6 +246,8 @@ pandas 0.11.0 - Add comparison operators to Period object (GH2781_) - Fix bug when concatenating two Series into a DataFrame when they have the same name (GH2797_) + - fix automatic color cycling when plotting consecutive timeseries + without color arguments (GH2816_) .. _GH622: https://github.com/pydata/pandas/issues/622 .. _GH797: https://github.com/pydata/pandas/issues/797 @@ -329,6 +331,9 @@ pandas 0.11.0 .. _GH3178: https://github.com/pydata/pandas/issues/3178 .. _GH3179: https://github.com/pydata/pandas/issues/3179 .. _GH3189: https://github.com/pydata/pandas/issues/3189 +.. _GH2751: https://github.com/pydata/pandas/issues/2751 +.. _GH2747: https://github.com/pydata/pandas/issues/2747 +.. _GH2816: https://github.com/pydata/pandas/issues/2816 pandas 0.10.1 =============