MCPcopy
hub / github.com/matplotlib/matplotlib / _process_plot_format

Function _process_plot_format

lib/matplotlib/axes/_base.py:122–202  ·  view source on GitHub ↗

Convert a MATLAB style color/line style format string to a (*linestyle*, *marker*, *color*) tuple. Example format strings include: * 'ko': black circles * '.b': blue dots * 'r--': red dashed lines * 'C2--': the third color in the color cycle, dashed lines The form

(fmt, *, ambiguous_fmt_datakey=False)

Source from the content-addressed store, hash-verified

120
121
122def _process_plot_format(fmt, *, ambiguous_fmt_datakey=False):
123 """
124 Convert a MATLAB style color/line style format string to a (*linestyle*,
125 *marker*, *color*) tuple.
126
127 Example format strings include:
128
129 * 'ko': black circles
130 * '.b': blue dots
131 * 'r--': red dashed lines
132 * 'C2--': the third color in the color cycle, dashed lines
133
134 The format is absolute in the sense that if a linestyle or marker is not
135 defined in *fmt*, there is no line or marker. This is expressed by
136 returning 'None' for the respective quantity.
137
138 See Also
139 --------
140 matplotlib.Line2D.lineStyles, matplotlib.colors.cnames
141 All possible styles and color format strings.
142 """
143
144 linestyle = None
145 marker = None
146 color = None
147
148 # First check whether fmt is just a colorspec, but specifically exclude the
149 # grayscale string "1" (not "1.0"), which is interpreted as the tri_down
150 # marker "1". The grayscale string "0" could be unambiguously understood
151 # as a color (black) but also excluded for consistency.
152 if fmt not in ["0", "1"]:
153 try:
154 color = mcolors.to_rgba(fmt)
155 return linestyle, marker, color
156 except ValueError:
157 pass
158
159 errfmt = ("{!r} is neither a data key nor a valid format string ({})"
160 if ambiguous_fmt_datakey else
161 "{!r} is not a valid format string ({})")
162
163 i = 0
164 while i < len(fmt):
165 c = fmt[i]
166 if fmt[i:i+2] in mlines.lineStyles: # First, the two-char styles.
167 if linestyle is not None:
168 raise ValueError(errfmt.format(fmt, "two linestyle symbols"))
169 linestyle = fmt[i:i+2]
170 i += 2
171 elif c in mlines.lineStyles:
172 if linestyle is not None:
173 raise ValueError(errfmt.format(fmt, "two linestyle symbols"))
174 linestyle = c
175 i += 1
176 elif c in mlines.lineMarkers:
177 if marker is not None:
178 raise ValueError(errfmt.format(fmt, "two marker symbols"))
179 marker = c

Callers 5

stemMethod · 0.90
stemMethod · 0.90
boxplotMethod · 0.90
__call__Method · 0.85
_plot_argsMethod · 0.85

Calls 1

to_rgbaMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…