Skip to content

Cleanup code for format processing #19291

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
Jan 18, 2021
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
17 changes: 9 additions & 8 deletions lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,6 @@ def __call__(self, ax, renderer):
self._transform - ax.figure.transSubfigure)


_FORMAT_UNSET = 'None'


def _process_plot_format(fmt):
"""
Convert a MATLAB style color/line style format string to a (*linestyle*,
Expand All @@ -134,7 +131,7 @@ def _process_plot_format(fmt):

The format is absolute in the sense that if a linestyle or marker is not
defined in *fmt*, there is no line or marker. This is expressed by
returning _FORMAT_UNSET for the respective quantity.
returning 'None' for the respective quantity.

See Also
--------
Expand Down Expand Up @@ -203,9 +200,9 @@ def _process_plot_format(fmt):
if linestyle is None and marker is None:
linestyle = mpl.rcParams['lines.linestyle']
if linestyle is None:
linestyle = _FORMAT_UNSET
linestyle = 'None'
if marker is None:
marker = _FORMAT_UNSET
marker = 'None'

return linestyle, marker, color

Expand Down Expand Up @@ -471,13 +468,17 @@ def _plot_args(self, tup, kwargs, return_kwargs=False):
# check for conflicts between fmt and kwargs
if (fmt.lower() != 'none'
and prop_name in kwargs
and val != _FORMAT_UNSET):
and val != 'None'):
# Technically ``plot(x, y, 'o', ls='--')`` is a conflict
# because 'o' implicitly unsets the linestyle
# (linestyle=_FORMAT_UNSET).
# (linestyle='None').
# We'll gracefully not warn in this case because an
# explicit set via kwargs can be seen as intention to
# override an implicit unset.
# Note: We don't val.lower() != 'none' because val is not
# necessarily a string (can be a tuple for colors). This
# is safe, because *val* comes from _process_plot_format()
# which only returns 'None'.
_api.warn_external(
f"{prop_name} is redundantly defined by the "
f"'{prop_name}' keyword argument and the fmt string "
Expand Down