|
49 | 49 |
|
50 | 50 |
|
51 | 51 | def _plot_args_replacer(args, data):
|
52 |
| - _replacer = [] |
53 |
| - remaining = args |
54 |
| - while 1: |
55 |
| - if len(remaining) == 1: |
56 |
| - |
57 |
| - msg = ("Missing argument: this can happen if a color spec " |
58 |
| - "('c') is in `data`") |
59 |
| - warnings.warn(msg, RuntimeWarning, stacklevel=3) |
60 |
| - _replacer += ["x"] |
61 |
| - elif len(remaining) == 2: |
62 |
| - _replacer += ["x", "y"] |
63 |
| - elif len(remaining) == 3: |
64 |
| - if remaining[2] in data: |
| 52 | + if len(args) == 1: |
| 53 | + return ["y"] |
| 54 | + elif len(args) == 2: |
| 55 | + # this can be two cases: x,y or y,c |
| 56 | + if not args[1] in data: |
| 57 | + # this is not in data, so just assume that it is something which |
| 58 | + # will not get replaced (color spec or array like). |
| 59 | + return ["y", "c"] |
| 60 | + # it's data, but could be a color code like 'ro' or 'b--' |
| 61 | + # -> warn the user in that case... |
| 62 | + arg2 = args[1] |
| 63 | + if is_string_like(arg2) and len(arg2) <= 3: |
| 64 | + # all possible linestyles and color codes -> see doc of plot |
| 65 | + reserved_ls = ["-", "--", "-.", ":", ".", ",", "o", "v", "^", "<", |
| 66 | + ">", "1", "2", "3", "4", "s", "p", "*", "h", "H", |
| 67 | + "+", "x", "D", "d", "|", "_"] |
| 68 | + reserved_cc = ["b", "r", "c", "m", "y", "k", "w"] |
| 69 | + # remove the line style part |
| 70 | + for ls in reserved_ls: |
| 71 | + if ls in arg2: |
| 72 | + arg2 = arg2.replace(ls, '') |
| 73 | + continue |
| 74 | + # can now only be a color code... |
| 75 | + if arg2 in reserved_cc: |
65 | 76 | import warnings
|
66 |
| - |
67 |
| - msg = "Found a color spec ('c') in data." |
| 77 | + msg = "Second argument is ambiguous: could be a color spec " \ |
| 78 | + "but is in data. Using as data.\nEither rename the " \ |
| 79 | + "entry in data or use three arguments to plot." |
68 | 80 | warnings.warn(msg, RuntimeWarning, stacklevel=3)
|
69 |
| - _replacer += ["x", "y", "c"] |
70 |
| - |
71 |
| - # if less than 3, the above code handled it so just return |
72 |
| - if len(remaining) <= 3: |
73 |
| - return _replacer |
74 |
| - |
75 |
| - # More than 3 -> split off the beginning and continue |
76 |
| - if remaining[2] not in data: |
77 |
| - _replacer += ["x", "y", "c"] |
78 |
| - isplit = 3 |
79 |
| - else: |
80 |
| - _replacer += ["x", "y"] |
81 |
| - isplit = 2 |
82 |
| - remaining = remaining[isplit:] |
| 81 | + return ["x", "y"] |
| 82 | + elif len(args) == 3: |
| 83 | + return ["x", "y", "c"] |
| 84 | + else: |
| 85 | + raise ValueError("Using arbitrary long args with data is not " |
| 86 | + "supported due to ambiguity of arguments.\nUse " |
| 87 | + "multiple plotting calls instead.") |
83 | 88 |
|
84 | 89 |
|
85 | 90 | # The axes module contains all the wrappers to plotting functions.
|
86 | 91 | # All the other methods should go in the _AxesBase class.
|
87 | 92 |
|
| 93 | + |
88 | 94 | class Axes(_AxesBase):
|
89 | 95 | """
|
90 | 96 | The :class:`Axes` contains most of the figure elements:
|
@@ -1305,8 +1311,14 @@ def plot(self, *args, **kwargs):
|
1305 | 1311 | If *x* and/or *y* is 2-dimensional, then the corresponding columns
|
1306 | 1312 | will be plotted.
|
1307 | 1313 |
|
1308 |
| - An arbitrary number of *x*, *y*, *fmt* groups can be |
1309 |
| - specified, as in:: |
| 1314 | + If used with labeled data, make sure that the color spec is not |
| 1315 | + included as an element in data, as otherwise the last case |
| 1316 | + ``plot("v","r", data={"v":..., "r":...)`` |
| 1317 | + can be interpreted as the first case which would do ``plot(v, r)`` |
| 1318 | + using the default line style and color. |
| 1319 | +
|
| 1320 | + If not used with labeled data (i.e., without a data argument), |
| 1321 | + an arbitrary number of *x*, *y*, *fmt* groups can be specified, as in:: |
1310 | 1322 |
|
1311 | 1323 | a.plot(x1, y1, 'g^', x2, y2, 'g-')
|
1312 | 1324 |
|
|
0 commit comments