|
34 | 34 |
|
35 | 35 | def _process_plot_format(fmt): |
36 | 36 | """ |
37 | | - Process a MATLAB style color/line style format string. Return a |
38 | | - (*linestyle*, *color*) tuple as a result of the processing. Default |
39 | | - values are ('-', 'b'). Example format strings include: |
| 37 | + Convert a MATLAB style color/line style format string to a (*linestyle*, |
| 38 | + *marker*, *color*) tuple. |
| 39 | +
|
| 40 | + Example format strings include: |
40 | 41 |
|
41 | 42 | * 'ko': black circles |
42 | 43 | * '.b': blue dots |
@@ -73,46 +74,40 @@ def _process_plot_format(fmt): |
73 | 74 | except ValueError: |
74 | 75 | pass # No, not just a color. |
75 | 76 |
|
76 | | - # handle the multi char special cases and strip them from the |
77 | | - # string |
78 | | - if fmt.find('--') >= 0: |
79 | | - linestyle = '--' |
80 | | - fmt = fmt.replace('--', '') |
81 | | - if fmt.find('-.') >= 0: |
82 | | - linestyle = '-.' |
83 | | - fmt = fmt.replace('-.', '') |
84 | | - if fmt.find(' ') >= 0: |
85 | | - linestyle = 'None' |
86 | | - fmt = fmt.replace(' ', '') |
87 | | - |
88 | | - chars = [c for c in fmt] |
89 | | - |
90 | 77 | i = 0 |
91 | | - while i < len(chars): |
92 | | - c = chars[i] |
93 | | - if c in mlines.lineStyles: |
| 78 | + while i < len(fmt): |
| 79 | + c = fmt[i] |
| 80 | + if fmt[i:i+2] in mlines.lineStyles: # First, the two-char styles. |
| 81 | + if linestyle is not None: |
| 82 | + raise ValueError( |
| 83 | + 'Illegal format string "%s"; two linestyle symbols' % fmt) |
| 84 | + linestyle = fmt[i:i+2] |
| 85 | + i += 2 |
| 86 | + elif c in mlines.lineStyles: |
94 | 87 | if linestyle is not None: |
95 | 88 | raise ValueError( |
96 | 89 | 'Illegal format string "%s"; two linestyle symbols' % fmt) |
97 | 90 | linestyle = c |
| 91 | + i += 1 |
98 | 92 | elif c in mlines.lineMarkers: |
99 | 93 | if marker is not None: |
100 | 94 | raise ValueError( |
101 | 95 | 'Illegal format string "%s"; two marker symbols' % fmt) |
102 | 96 | marker = c |
| 97 | + i += 1 |
103 | 98 | elif c in mcolors.get_named_colors_mapping(): |
104 | 99 | if color is not None: |
105 | 100 | raise ValueError( |
106 | 101 | 'Illegal format string "%s"; two color symbols' % fmt) |
107 | 102 | color = c |
108 | | - elif c == 'C' and i < len(chars) - 1: |
109 | | - color_cycle_number = int(chars[i + 1]) |
110 | | - color = mcolors.to_rgba("C{}".format(color_cycle_number)) |
111 | 103 | i += 1 |
| 104 | + elif c == 'C' and i < len(fmt) - 1: |
| 105 | + color_cycle_number = int(fmt[i + 1]) |
| 106 | + color = mcolors.to_rgba("C{}".format(color_cycle_number)) |
| 107 | + i += 2 |
112 | 108 | else: |
113 | 109 | raise ValueError( |
114 | 110 | 'Unrecognized character %c in format string' % c) |
115 | | - i += 1 |
116 | 111 |
|
117 | 112 | if linestyle is None and marker is None: |
118 | 113 | linestyle = rcParams['lines.linestyle'] |
|
0 commit comments