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

Skip to content

Commit bfec0e7

Browse files
committed
Improve warning for case where data kwarg entry is ambiguous.
A call like `plot("x", "y", data={"x": ..., "y": ...})` currently results in a warning suggesting to use a 3-arg call or renaming the entry, because "y" is ambiguous. Renaming the entry is not always an option (if you do not control 'data'), and it may not be obvious how to do a 3-arg call that just uses the normal property cycle. As it turns out, passing an empty string works, so document that possibility.
1 parent 52aa26b commit bfec0e7

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

lib/matplotlib/axes/_base.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,13 @@ def __call__(self, *args, **kwargs):
194194
else:
195195
if replaced[1] is not args[1]: # case 2a)
196196
cbook._warn_external(
197-
"Second argument {!r} is ambiguous: could be a "
198-
"color spec but is in data; using as data. "
199-
"Either rename the entry in data or use three "
200-
"arguments to plot.".format(args[1]),
197+
f"Second argument {args[1]!r} is ambiguous: could "
198+
f"be a format string but is in 'data'; using as "
199+
f"data. If it was intended as data, set the "
200+
f"format string to an empty string to suppress "
201+
f"this warning. If it was intended as a format "
202+
f"string, explicitly pass the x-values as well. "
203+
f"Alternatively, rename the entry in 'data'.",
201204
RuntimeWarning)
202205
label_namer_idx = 1
203206
else: # case 2b)

0 commit comments

Comments
 (0)