Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions lib/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1529,6 +1529,9 @@ def _replacer(data, key):
following arguments are replaced by **data[<arg>]**:

{replaced}

Objects passed as **data** must support item access (``data[<arg>]``) and
membership test (``<arg> in data``).
"""


Expand Down
20 changes: 13 additions & 7 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,24 @@
rcParams = matplotlib.rcParams


def _has_item(data, name):
"""Return whether *data* can be item-accessed with *name*.

This supports data with a dict-like interface (`in` checks item
availability) and with numpy.arrays.
"""
try:
return data.dtype.names is not None and name in data.dtype.names
except AttributeError: # not a numpy array
return name in data


def _plot_args_replacer(args, data):
if len(args) == 1:
return ["y"]
elif len(args) == 2:
# this can be two cases: x,y or y,c
if (not args[1] in data and
not (hasattr(data, 'dtype') and
hasattr(data.dtype, 'names') and
data.dtype.names is not None and
args[1] in data.dtype.names)):
# this is not in data, so just assume that it is something which
# will not get replaced (color spec or array like).
if not _has_item(data, args[1]):
return ["y", "c"]
# it's data, but could be a color code like 'ro' or 'b--'
# -> warn the user in that case...
Expand Down