Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Remove hardcoded colors in pie()
  • Loading branch information
mdboom committed Nov 30, 2015
commit 568042b2e8a146c302aeb5ed7bddebdb8fe63e23
15 changes: 12 additions & 3 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from matplotlib.externals.six.moves import reduce, xrange, zip, zip_longest

import math
import itertools
import warnings

import numpy as np
Expand Down Expand Up @@ -2446,7 +2447,7 @@ def pie(self, x, explode=None, labels=None, colors=None,
Call signature::

pie(x, explode=None, labels=None,
colors=('b', 'g', 'r', 'c', 'm', 'y', 'k', 'w'),
colors=None,
autopct=None, pctdistance=0.6, shadow=False,
labeldistance=1.1, startangle=None, radius=None,
counterclock=True, wedgeprops=None, textprops=None,
Expand Down Expand Up @@ -2554,8 +2555,16 @@ def pie(self, x, explode=None, labels=None, colors=None,
raise ValueError("'label' must be of length 'x'")
if len(x) != len(explode):
raise ValueError("'explode' must be of length 'x'")
if colors is None:
if ((colors is None) and
('color' in self._get_patches_for_fill._prop_keys)):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indent to not line up with codeblock

def get_next_color():
return six.next(self._get_patches_for_fill.prop_cycler)['color']
elif colors is None:
colors = ('b', 'g', 'r', 'c', 'm', 'y', 'k', 'w')
if colors is not None:
color_cycler = itertools.cycle(colors)
def get_next_color():
return six.next(color_cycler)

if radius is None:
radius = 1
Expand Down Expand Up @@ -2591,7 +2600,7 @@ def pie(self, x, explode=None, labels=None, colors=None,

w = mpatches.Wedge((x, y), radius, 360. * min(theta1, theta2),
360. * max(theta1, theta2),
facecolor=colors[i % len(colors)],
facecolor=get_next_color(),
**wedgeprops)
slices.append(w)
self.add_patch(w)
Expand Down