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

Skip to content

Commit ced56dd

Browse files
committed
Support [N] syntax in rcParams file
1 parent 83342fe commit ced56dd

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

lib/matplotlib/colors.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
- w: white
3333
3434
To use the colors that are part of the active color cycle in the
35-
current style, use a string with the color number in square brackets.
35+
current style, use a string with a positive index in square brackets.
36+
If the index is larger than the color cycle, it is wrapped around.
3637
For example:
3738
3839
- `[0]`: The first color in the cycle
@@ -220,6 +221,13 @@
220221

221222
def is_color_like(c):
222223
'Return *True* if *c* can be converted to *RGB*'
224+
# Special-case the N-th color cycle syntax, because it's parsing
225+
# needs to be deferred. We may be reading a value from rcParams
226+
# here before the color_cycle rcParam has been parsed.
227+
match = re.match('^\[[0-9]\]$', c)
228+
if match is not None:
229+
return True
230+
223231
try:
224232
colorConverter.to_rgb(c)
225233
return True

lib/matplotlib/rcsetup.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,7 @@ def validate_hist_bins(s):
827827
# line props
828828
'lines.linewidth': [1.0, validate_float], # line width in points
829829
'lines.linestyle': ['-', six.text_type], # solid line
830-
'lines.color': ['b', validate_color], # blue
830+
'lines.color': ['[0]', validate_color], # blue
831831
'lines.marker': ['None', six.text_type], # black
832832
'lines.markeredgewidth': [1.0, validate_float],
833833
'lines.markersize': [6, validate_float], # markersize, in points
@@ -843,7 +843,7 @@ def validate_hist_bins(s):
843843
## patch props
844844
'patch.linewidth': [None, validate_float_or_None], # line width in points
845845
'patch.edgecolor': ['k', validate_color], # black
846-
'patch.facecolor': ['b', validate_color], # blue
846+
'patch.facecolor': ['[0]', validate_color], # blue
847847
'patch.antialiased': [True, validate_bool], # antialiased (no jaggies)
848848

849849
## Histogram properties
@@ -992,9 +992,6 @@ def validate_hist_bins(s):
992992
'axes.formatter.use_mathtext': [False, validate_bool],
993993
'axes.formatter.useoffset': [True, validate_bool],
994994
'axes.unicode_minus': [True, validate_bool],
995-
'axes.color_cycle': [['b', 'g', 'r', 'c', 'm', 'y', 'k'],
996-
deprecate_axes_colorcycle], # cycle of plot
997-
# line colors
998995
# This entry can be either a cycler object or a
999996
# string repr of a cycler-object, which gets eval()'ed
1000997
# to create the object.

0 commit comments

Comments
 (0)