Skip to content

BUG: automatic color cycling when plotting Series without style or color argument (fixes #2816) #2836

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions RELEASE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,16 @@ pandas 0.11.0
(e.g. np.array(datetime(2001,1,1,0,0))), w/o dtype being passed
- 0-dim ndarrays with a passed dtype are handled correctly
(e.g. np.array(0.,dtype='float32'))
- 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
.. _GH2778: https://github.com/pydata/pandas/issues/2778
.. _GH2793: https://github.com/pydata/pandas/issues/2793
.. _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
=============
Expand Down
12 changes: 12 additions & 0 deletions pandas/tests/test_graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,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
Expand Down
11 changes: 8 additions & 3 deletions pandas/tools/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,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
Expand Down Expand Up @@ -1063,13 +1065,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):
Expand Down Expand Up @@ -2077,6 +2078,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
Expand All @@ -2094,6 +2097,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

Expand Down