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

Skip to content

WIP: Use color cycle in more places #5584

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 7 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
34 changes: 25 additions & 9 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,9 +2555,20 @@ 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
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 +2603,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 Expand Up @@ -2859,6 +2871,10 @@ def xywhere(xs, ys, mask):
ys = [thisy for thisy, b in zip(ys, mask) if b]
return xs, ys

# Set an explicit color so the color cycle doesn't advance. It
# will be set to the correct color where `ecolor` is handled
# below.
kwargs['color'] = 'k'
plot_kw = {'label': '_nolegend_'}
if capsize is None:
capsize = rcParams["errorbar.capsize"]
Expand All @@ -2873,7 +2889,8 @@ def xywhere(xs, ys, mask):
plot_kw['markeredgewidth'] = capthick
# For backwards-compat, allow explicit setting of
# 'mew' or 'markeredgewidth' to over-ride capthick.
for key in ('markeredgewidth', 'mew', 'transform', 'alpha', 'zorder'):
for key in ('markeredgewidth', 'mew', 'transform', 'alpha', 'zorder',
'color'):
if key in kwargs:
plot_kw[key] = kwargs[key]

Expand Down Expand Up @@ -3010,16 +3027,15 @@ def xywhere(xs, ys, mask):
if not barsabove and plot_line:
l0, = self.plot(x, y, fmt, label='_nolegend_', **kwargs)

if ecolor is None:
if l0 is None and 'color' in self._get_lines._prop_keys:
ecolor = six.next(self._get_lines.prop_cycler)['color']
else:
ecolor = l0.get_color()
if 'color' in self._get_lines._prop_keys:
ecolor = six.next(self._get_lines.prop_cycler)['color']

for l in barcols:
l.set_color(ecolor)
for l in caplines:
l.set_color(ecolor)
if l0 is not None:
l0.set_color(ecolor)
Copy link
Member

Choose a reason for hiding this comment

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

Why is this stuff getting changed? It is already using the property cycle.

Copy link
Member Author

Choose a reason for hiding this comment

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

In order to make sure that all of the pieces of the errorbar have the same color, we have to forcibly set the colors at the end. I realised since that by not using plt.plot internally but by using Axes.line2d directly we can probably avoid all this nonsense.


self.autoscale_view()
self._hold = holdstate
Expand Down
2 changes: 2 additions & 0 deletions lib/matplotlib/mpl-data/stylelib/classic.mplstyle
Original file line number Diff line number Diff line change
Expand Up @@ -495,3 +495,5 @@ animation.convert_path: convert # Path to ImageMagick's convert binary.
# is also the name of a system tool.
animation.convert_args:
animation.html: none

_internal.classic_mode: True
29 changes: 20 additions & 9 deletions lib/matplotlib/rcsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -965,14 +965,18 @@ def validate_cycler(s):
# This entry can be either a cycler object or a
# string repr of a cycler-object, which gets eval()'ed
# to create the object.
'axes.prop_cycle': [ccycler('color', 'bgrcmyk'),
validate_cycler],
'axes.xmargin': [0, ValidateInterval(0, 1,
closedmin=True,
closedmax=True)], # margin added to xaxis
'axes.ymargin': [0, ValidateInterval(0, 1,
closedmin=True,
closedmax=True)],# margin added to yaxis
'axes.prop_cycle': [
ccycler('color',
['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728',
'#9467bd', '#8c564b', '#e377c2', '#7f7f7f',
'#bcbd22', '#17becf']),
validate_cycler],
'axes.xmargin': [0.05, ValidateInterval(0, 1,
closedmin=True,
closedmax=True)], # margin added to xaxis
'axes.ymargin': [0.05, ValidateInterval(0, 1,
closedmin=True,
closedmax=True)],# margin added to yaxis

'polaraxes.grid': [True, validate_bool], # display polar grid or
# not
Expand Down Expand Up @@ -1191,7 +1195,14 @@ def validate_cycler(s):
'animation.convert_path': ['convert', six.text_type],
# Additional arguments for mencoder movie writer (using pipes)

'animation.convert_args': [[], validate_stringlist]}
'animation.convert_args': [[], validate_stringlist],

# Classic (pre 2.0) compatibility mode
# This is used for things that are hard to make backward compatible
# with a sane rcParam alone. This does *not* turn on classic mode
# altogether. For that use `matplotlib.style.use('classic')`.
'_internal.classic_mode': [False, validate_bool]
}


if __name__ == '__main__':
Expand Down
17 changes: 10 additions & 7 deletions lib/matplotlib/sankey.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
from matplotlib.transforms import Affine2D
from matplotlib import verbose
from matplotlib import docstring
from matplotlib import rcParams

__author__ = "Kevin L. Davies"
__credits__ = ["Yannick Copin"]
Expand Down Expand Up @@ -444,8 +445,6 @@ def add(self, patchlabel='', flows=None, orientations=None, labels='',
%(Patch)s

As examples, ``fill=False`` and ``label='A legend entry'``.
By default, ``facecolor='#bfd1d4'`` (light blue) and
``linewidth=0.5``.

The indexing parameters (*prior* and *connect*) are zero-based.

Expand Down Expand Up @@ -770,11 +769,15 @@ def _get_angle(a, r):
print("lrpath\n", self._revert(lrpath))
xs, ys = list(zip(*vertices))
self.ax.plot(xs, ys, 'go-')
patch = PathPatch(Path(vertices, codes),
fc=kwargs.pop('fc', kwargs.pop('facecolor',
'#bfd1d4')), # Custom defaults
lw=kwargs.pop('lw', kwargs.pop('linewidth', 0.5)),
**kwargs)
if rcParams['_internal.classic_mode']:
fc = kwargs.pop('fc', kwargs.pop('facecolor', '#bfd1d4'))
lw = kwargs.pop('lw', kwargs.pop('linewidth', 0.5))
else:
fc = kwargs.pop('fc', kwargs.pop('facecolor', None))
lw = kwargs.pop('lw', kwargs.pop('linewidth', None))
if fc is None:
fc = six.next(self.ax._get_patches_for_fill.prop_cycler)['color']
patch = PathPatch(Path(vertices, codes), fc=fc, lw=lw, **kwargs)
self.ax.add_patch(patch)

# Add the path labels.
Expand Down
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading