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

Skip to content

Simplify color/marker disambiguation logic in _process_plot_format. #27829

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 8 additions & 16 deletions lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,24 +143,16 @@ def _process_plot_format(fmt, *, ambiguous_fmt_datakey=False):
marker = None
color = None

# Is fmt just a colorspec?
try:
color = mcolors.to_rgba(fmt)

# We need to differentiate grayscale '1.0' from tri_down marker '1'
# First check whether fmt is just a colorspec, but specifically exclude the
# grayscale string "1" (not "1.0"), which is interpreted as the tri_down
# marker "1". The grayscale string "0" could be unambiguously understood
# as a color (black) but also excluded for consistency.
if fmt not in ["0", "1"]:
try:
fmtint = str(int(fmt))
color = mcolors.to_rgba(fmt)
return linestyle, marker, color
except ValueError:
return linestyle, marker, color # Yes
else:
if fmt != fmtint:
# user definitely doesn't want tri_down marker
return linestyle, marker, color # Yes
else:
# ignore converted color
color = None
except ValueError:
pass # No, not just a color.
pass

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