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

Skip to content

Commit d350e56

Browse files
committed
Simplify color/marker disambiguation logic in _process_plot_format.
There's a bit of code in the parsing of plot() format shorthands to disambiguate the "1" marker and the "1.0" grayscale color string. It's actually easier to just explicitly check for the bad strings. This also makes it clearer that we *could* have supported "0" as unambiguous color string (white) as there's no "0" marker (there's a 0 (int) marker, which is not the same...), but let's not bother with changing any semantics.
1 parent bf6cc30 commit d350e56

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -143,24 +143,16 @@ def _process_plot_format(fmt, *, ambiguous_fmt_datakey=False):
143143
marker = None
144144
color = None
145145

146-
# Is fmt just a colorspec?
147-
try:
148-
color = mcolors.to_rgba(fmt)
149-
150-
# We need to differentiate grayscale '1.0' from tri_down marker '1'
146+
# First check whether fmt is just a colorspec, but specifically exclude the
147+
# grayscale string "1" (not "1.0"), which is interpreted as the tri_down
148+
# marker "1". The grayscale string "0" could be unambiguously understood
149+
# as a color (black) but also excluded for consistency.
150+
if fmt not in ["0", "1"]:
151151
try:
152-
fmtint = str(int(fmt))
152+
color = mcolors.to_rgba(fmt)
153+
return linestyle, marker, color
153154
except ValueError:
154-
return linestyle, marker, color # Yes
155-
else:
156-
if fmt != fmtint:
157-
# user definitely doesn't want tri_down marker
158-
return linestyle, marker, color # Yes
159-
else:
160-
# ignore converted color
161-
color = None
162-
except ValueError:
163-
pass # No, not just a color.
155+
pass
164156

165157
errfmt = ("{!r} is neither a data key nor a valid format string ({})"
166158
if ambiguous_fmt_datakey else

0 commit comments

Comments
 (0)