File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1524,6 +1524,9 @@ def _replacer(data, key):
15241524 following arguments are replaced by **data[<arg>]**:
15251525
15261526 {replaced}
1527+
1528+ Objects passed as **data** must support item access (``data[<arg>]``) and
1529+ membership test (``<arg> in data``).
15271530"""
15281531
15291532
Original file line number Diff line number Diff line change 4444rcParams = matplotlib .rcParams
4545
4646
47+ def _has_item (data , name ):
48+ """Return whether *data* can be item-accessed with *name*.
49+
50+ This supports data with a dict-like interface (`in` checks item
51+ availability) and with numpy.arrays.
52+ """
53+ try :
54+ return data .dtype .names is not None and name in data .dtype .names
55+ except AttributeError : # not a numpy array
56+ return name in data
57+
58+
4759def _plot_args_replacer (args , data ):
4860 if len (args ) == 1 :
4961 return ["y" ]
5062 elif len (args ) == 2 :
5163 # this can be two cases: x,y or y,c
52- if (not args [1 ] in data and
53- not (hasattr (data , 'dtype' ) and
54- hasattr (data .dtype , 'names' ) and
55- data .dtype .names is not None and
56- args [1 ] in data .dtype .names )):
57- # this is not in data, so just assume that it is something which
58- # will not get replaced (color spec or array like).
64+ if not _has_item (data , args [1 ]):
5965 return ["y" , "c" ]
6066 # it's data, but could be a color code like 'ro' or 'b--'
6167 # -> warn the user in that case...
You can’t perform that action at this time.
0 commit comments