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

Skip to content

Commit 8cd0afd

Browse files
committed
Added rcParams['axes.color_cycle']
svn path=/trunk/matplotlib/; revision=8066
1 parent 0bf23f2 commit 8cd0afd

6 files changed

Lines changed: 50 additions & 44 deletions

File tree

CHANGELOG

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
2010-01-03 Added rcParams['axes.color_cycle'] - EF
2+
13
2010-01-03 Added Pierre's qt4 formlayout editor and toolbar button - JDH
24

35
2009-12-31 Add support for using math text as marker symbols (Thanks to tcb)

doc/api/api_changes.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ list may help describe what changes may be necessary in your code.
1010
Changes beyond 0.99.x
1111
=====================
1212

13-
* You can now print several figures to one pdf file and modify the
13+
* There is a new rc parameter ``axes.color_cycle``, and the color
14+
cycle is now independent of the rc parameter ``lines.color``.
15+
:func:`matplotlib.Axes.set_default_color_cycle` is deprecated.
16+
17+
* You can now print several figures to one pdf file and modify the
1418
document information dictionary of a pdf file. See the docstrings
1519
of the class :class:`matplotlib.backends.backend_pdf.PdfPages` for
1620
more information.

examples/api/color_cycle.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
mpl.rc('lines', linewidth=4)
1414

1515
fig = plt.figure()
16-
mpl.axes.set_default_color_cycle(['r', 'g', 'b', 'c'])
16+
mpl.rcParams['axes.color_cycle'] = ['r', 'g', 'b', 'c']
1717
ax = fig.add_subplot(2,1,1)
1818
ax.plot(yy)
1919
ax.set_title('Changed default color cycle to rgbc')

lib/matplotlib/axes.py

Lines changed: 20 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from __future__ import division, generators
22
import math, sys, warnings, datetime, new
3+
from operator import itemgetter
4+
import itertools
35

46
import numpy as np
57
from numpy import ma
@@ -31,7 +33,6 @@
3133
import matplotlib.ticker as mticker
3234
import matplotlib.transforms as mtransforms
3335

34-
from operator import itemgetter
3536

3637
iterable = cbook.iterable
3738
is_string_like = cbook.is_string_like
@@ -115,11 +116,18 @@ def set_default_color_cycle(clist):
115116
:class:`Axes` to which it will apply; it will
116117
apply to all future axes.
117118
118-
*clist* is a sequence of mpl color specifiers
119+
*clist* is a sequence of mpl color specifiers.
120+
121+
See also: :meth:`~matplotlib.axes.Axes.set_color_cycle`.
122+
123+
.. Note:: Deprecated 2010/01/03.
124+
Set rcParams['axes.color_cycle'] directly.
119125
120126
"""
121-
_process_plot_var_args.defaultColors = clist[:]
122-
rcParams['lines.color'] = clist[0]
127+
rcParams['axes.color_cycle'] = clist
128+
warnings.warn("Set rcParams['axes.color_cycle'] directly",
129+
DeprecationWarning)
130+
123131

124132
class _process_plot_var_args:
125133
"""
@@ -134,42 +142,18 @@ class _process_plot_var_args:
134142
135143
an arbitrary number of *x*, *y*, *fmt* are allowed
136144
"""
137-
138-
defaultColors = ['b','g','r','c','m','y','k']
139145
def __init__(self, axes, command='plot'):
140146
self.axes = axes
141147
self.command = command
142-
self._clear_color_cycle()
143-
144-
def _clear_color_cycle(self):
145-
self.colors = _process_plot_var_args.defaultColors[:]
146-
# if the default line color is a color format string, move it up
147-
# in the que
148-
try:
149-
ind = self.colors.index(rcParams['lines.color'])
150-
except ValueError:
151-
self.firstColor = rcParams['lines.color']
152-
else:
153-
self.colors[0], self.colors[ind] = self.colors[ind], self.colors[0]
154-
self.firstColor = self.colors[0]
155-
156-
self.Ncolors = len(self.colors)
148+
self.set_color_cycle()
157149

158-
self.count = 0
159-
160-
def set_color_cycle(self, clist):
161-
self.colors = clist[:]
162-
self.firstColor = self.colors[0]
163-
self.Ncolors = len(self.colors)
164-
self.count = 0
150+
def set_color_cycle(self, clist=None):
151+
if clist is None:
152+
clist = rcParams['axes.color_cycle']
153+
self._colors = itertools.cycle(clist)
165154

166155
def _get_next_cycle_color(self):
167-
if self.count==0:
168-
color = self.firstColor
169-
else:
170-
color = self.colors[int(self.count % self.Ncolors)]
171-
self.count += 1
172-
return color
156+
return self._colors.next()
173157

174158
def __call__(self, *args, **kwargs):
175159

@@ -907,9 +891,10 @@ def set_color_cycle(self, clist):
907891
"""
908892
Set the color cycle for any future plot commands on this Axes.
909893
910-
clist is a list of mpl color specifiers.
894+
*clist* is a list of mpl color specifiers.
911895
"""
912896
self._get_lines.set_color_cycle(clist)
897+
self._get_patches_for_fill.set_color_cycle(clist)
913898

914899

915900
def ishold(self):

lib/matplotlib/rcsetup.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,14 @@ def validate_color(s):
207207

208208
raise ValueError('%s does not look like a color arg%s'%(s, msg))
209209

210+
def validate_colorlist(s):
211+
'return a list of colorspecs'
212+
if type(s) is str:
213+
return [validate_color(c.strip()) for c in s.split(',')]
214+
else:
215+
assert type(s) in [list, tuple]
216+
return [validate_color(c) for c in s]
217+
210218
def validate_stringlist(s):
211219
'return a list'
212220
if type(s) is str:
@@ -440,6 +448,9 @@ def __call__(self, s):
440448
# of the axis range is smaller than the
441449
# first or larger than the second
442450
'axes.unicode_minus' : [True, validate_bool],
451+
'axes.color_cycle' : [['b','g','r','c','m','y','k'],
452+
validate_colorlist], # cycle of plot
453+
# line colors
443454

444455
'polaraxes.grid' : [True, validate_bool], # display polar grid or not
445456
'axes3d.grid' : [True, validate_bool], # display 3d grid

matplotlibrc.template

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,11 @@ backend : %(backend)s
161161
#text.markup : 'plain' # Affects how text, such as titles and labels, are
162162
# interpreted by default.
163163
# 'plain': As plain, unformatted text
164-
# 'tex': As TeX-like text. Text between $'s will be
165-
# formatted as a TeX math expression.
166-
# This setting has no effect when text.usetex is True.
167-
# In that case, all text will be sent to TeX for
168-
# processing.
164+
# 'tex': As TeX-like text. Text between $'s will be
165+
# formatted as a TeX math expression.
166+
# This setting has no effect when text.usetex is True.
167+
# In that case, all text will be sent to TeX for
168+
# processing.
169169

170170
#text.hinting : True # If True, text will be hinted, otherwise not. This only
171171
# affects the Agg backend.
@@ -184,8 +184,8 @@ backend : %(backend)s
184184
#mathtext.fontset : cm # Should be 'cm' (Computer Modern), 'stix',
185185
# 'stixsans' or 'custom'
186186
#mathtext.fallback_to_cm : True # When True, use symbols from the Computer Modern
187-
# fonts when a symbol can not be found in one of
188-
# the custom math fonts.
187+
# fonts when a symbol can not be found in one of
188+
# the custom math fonts.
189189

190190
#mathtext.default : it # The default font to use for math.
191191
# Can be any of the LaTeX font names, including
@@ -211,6 +211,10 @@ backend : %(backend)s
211211
# first or larger than the second
212212
#axes.unicode_minus : True # use unicode for the minus symbol
213213
# rather than hypen. See http://en.wikipedia.org/wiki/Plus_sign#Plus_sign
214+
#axes.color_cycle : b, g, r, c, m, y, k # color cycle for plot lines
215+
# as list of string colorspecs:
216+
# single letter, long name, or
217+
# web-style hex
214218

215219
#polaraxes.grid : True # display grid on polar axes
216220
#axes3d.grid : True # display grid on 3d axes

0 commit comments

Comments
 (0)