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

Skip to content

Commit 42472ef

Browse files
authored
Merge pull request #27829 from anntzer/ppf
Simplify color/marker disambiguation logic in _process_plot_format.
2 parents 102d0a6 + d350e56 commit 42472ef

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
@@ -144,24 +144,16 @@ def _process_plot_format(fmt, *, ambiguous_fmt_datakey=False):
144144
marker = None
145145
color = None
146146

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

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

0 commit comments

Comments
 (0)