From e374f0ffda19d52ec5611ef49fdb84f3133517ed Mon Sep 17 00:00:00 2001 From: Chang She Date: Wed, 14 Nov 2012 01:04:34 -0500 Subject: [PATCH] BUG: axes.color_cycle from mpl rcParams should not be joined as single string --- pandas/tests/test_graphics.py | 15 +++++++++++++++ pandas/tools/plotting.py | 4 +++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/pandas/tests/test_graphics.py b/pandas/tests/test_graphics.py index 311295a9e2b88..0c5f1a6c3daa2 100644 --- a/pandas/tests/test_graphics.py +++ b/pandas/tests/test_graphics.py @@ -537,6 +537,21 @@ def test_line_colors(self): plt.close('all') df.ix[:, [0]].plot(color='DodgerBlue') + @slow + def test_default_color_cycle(self): + import matplotlib.pyplot as plt + plt.rcParams['axes.color_cycle'] = list('rgbk') + + plt.close('all') + df = DataFrame(np.random.randn(5, 3)) + ax = df.plot() + + lines = ax.get_lines() + for i, l in enumerate(lines): + xp = plt.rcParams['axes.color_cycle'][i] + rs = l.get_color() + self.assert_(xp == rs) + class TestDataFrameGroupByPlots(unittest.TestCase): diff --git a/pandas/tools/plotting.py b/pandas/tools/plotting.py index f12e2fcdf8d87..e61d1be9c824a 100644 --- a/pandas/tools/plotting.py +++ b/pandas/tools/plotting.py @@ -979,7 +979,9 @@ def _use_dynamic_x(self): def _get_colors(self): import matplotlib.pyplot as plt - cycle = ''.join(plt.rcParams.get('axes.color_cycle', list('bgrcmyk'))) + 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