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

Skip to content

Commit 6b2223d

Browse files
committed
Initial implementation of property cycling
* Changed name from style cycling to property cycling * Still not working for bar plots, though. * Need to test errorbars.
1 parent 160401b commit 6b2223d

3 files changed

Lines changed: 41 additions & 25 deletions

File tree

lib/matplotlib/axes/_axes.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,9 +1265,9 @@ def plot(self, *args, **kwargs):
12651265
12661266
Return value is a list of lines that were added.
12671267
1268-
By default, each line is assigned a different color specified by a
1269-
'color cycle'. To change this behavior, you can edit the
1270-
axes.color_cycle rcParam.
1268+
By default, each line is assigned a different style specified by a
1269+
'style cycle'. To change this behavior, you can edit the
1270+
axes.prop_cycle rcParam.
12711271
12721272
The following format string characters are accepted to control
12731273
the line style or marker:
@@ -2935,8 +2935,8 @@ def xywhere(xs, ys, mask):
29352935
l0, = self.plot(x, y, fmt, **kwargs)
29362936

29372937
if ecolor is None:
2938-
if l0 is None:
2939-
ecolor = six.next(self._get_lines.color_cycle)
2938+
if l0 is None and 'color' in self._get_lines._prop_keys:
2939+
ecolor = six.next(self._get_lines.prop_cycle)['color']
29402940
else:
29412941
ecolor = l0.get_color()
29422942

@@ -5829,8 +5829,8 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None,
58295829

58305830
nx = len(x) # number of datasets
58315831

5832-
if color is None:
5833-
color = [six.next(self._get_lines.color_cycle)
5832+
if color is None and 'color' in self._get_lines._prop_keys:
5833+
color = [six.next(self._get_lines.prop_cycle)['color']
58345834
for i in xrange(nx)]
58355835
else:
58365836
color = mcolors.colorConverter.to_rgba_array(color)

lib/matplotlib/axes/_base.py

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import math
1010
from operator import itemgetter
1111

12-
from cycler import cycler
12+
from cycler import cycler, Cycler
1313
import numpy as np
1414
from numpy import ma
1515

@@ -139,25 +139,25 @@ class _process_plot_var_args(object):
139139
def __init__(self, axes, command='plot'):
140140
self.axes = axes
141141
self.command = command
142-
self.set_style_cycle()
142+
self.set_prop_cycle()
143143

144144
def __getstate__(self):
145145
# note: it is not possible to pickle a itertools.cycle instance
146146
return {'axes': self.axes, 'command': self.command}
147147

148148
def __setstate__(self, state):
149149
self.__dict__ = state.copy()
150-
self.set_style_cycle()
150+
self.set_prop_cycle()
151151

152-
def set_style_cycle(self, style_cycler=None):
153-
if style_cycler is None:
154-
style_cycler = rcParams['axes.style_cycle']
155-
if style_cycler is None and 'axes.color_cycle' in rcParams:
152+
def set_prop_cycle(self, prop_cycler=None):
153+
if prop_cycler is None:
154+
prop_cycler = rcParams['axes.prop_cycle']
155+
if prop_cycler is None and 'axes.color_cycle' in rcParams:
156156
clist = rcParams['axes.color_cycle']
157-
style_cycler = cycler('color', clist)
158-
self.style_cycler = itertools.cycle(style_cycler)
157+
prop_cycler = cycler('color', clist)
158+
self.prop_cycler = itertools.cycle(prop_cycler)
159159
# Make a copy
160-
self._style_keys = list(style_cycler.keys)
160+
self._prop_keys = list(prop_cycler.keys)
161161

162162
def __call__(self, *args, **kwargs):
163163

@@ -240,12 +240,12 @@ def _setdefaults(self, kw, kwargs):
240240
# has information that is not specified
241241
# in the supplied kw and kwargs dicts
242242
if any([kw.get(k, None) is None and kwargs.get(k, None) is None
243-
for k in self._style_keys]):
244-
default_dict = six.next(self.style_cycler)
243+
for k in self._prop_keys]):
244+
default_dict = six.next(self.prop_cycler)
245245
else:
246246
default_dict = None
247247

248-
for k in self._style_keys:
248+
for k in self._prop_keys:
249249
if (default_dict is not None and
250250
kw.get(k, None) is None and
251251
kwargs.get(k, None) is None):
@@ -1004,14 +1004,30 @@ def clear(self):
10041004
"""clear the axes"""
10051005
self.cla()
10061006

1007+
def set_prop_cycle(self, prop_cycle):
1008+
"""
1009+
Set the prop cycle for any future plot commands on this Axes.
1010+
1011+
*prop_cycle* is a :class:Cycler object.
1012+
Can also be `None` to reset to the cycle defined by the
1013+
current style.
1014+
"""
1015+
self._get_lines.set_prop_cycle(prop_cycle)
1016+
self._get_patches_for_fill.set_prop_cycle(prop_cycle)
1017+
10071018
def set_color_cycle(self, clist):
10081019
"""
10091020
Set the color cycle for any future plot commands on this Axes.
10101021
10111022
*clist* is a list of mpl color specifiers.
1023+
1024+
.. deprecated:: 1.5
10121025
"""
1013-
self._get_lines.set_color_cycle(clist)
1014-
self._get_patches_for_fill.set_color_cycle(clist)
1026+
cbook.warn_deprecated(
1027+
'1.5', name='set_color_cycle', alternative='set_prop_cycle')
1028+
prop_cycler = cycler('color', clist)
1029+
self._get_lines.set_prop_cycle(prop_cycler)
1030+
self._get_patches_for_fill.set_prop_cycle(prop_cycler)
10151031

10161032
def ishold(self):
10171033
"""return the HOLD status of the axes"""

lib/matplotlib/rcsetup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ def validate_color(s):
302302
raise ValueError('%s does not look like a color arg%s' % (s, msg))
303303

304304
def deprecate_axes_colorcycle(value):
305-
warnings.warn("axes.color_cycle is deprecated. Use axes.style_cycle "
305+
warnings.warn("axes.color_cycle is deprecated. Use axes.prop_cycle "
306306
"instead. Will be removed in 2.1.0")
307307
return validate_colorlist(value)
308308

@@ -780,8 +780,8 @@ def __call__(self, s):
780780
# This entry can be either a cycler object or a
781781
# string repr of a cycler-object, which gets eval()'ed
782782
# to create the object.
783-
'axes.style_cycle': [cycler('color', 'bgrcmyk'),
784-
validate_cycler],
783+
'axes.prop_cycle': [cycler('color', 'bgrcmyk'),
784+
validate_cycler],
785785
'axes.xmargin': [0, ValidateInterval(0, 1,
786786
closedmin=True,
787787
closedmax=True)], # margin added to xaxis

0 commit comments

Comments
 (0)