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

Skip to content

Commit 1f8bad2

Browse files
committed
bugfix for #8818
1 parent cc7d086 commit 1f8bad2

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,22 +55,24 @@ def _plot_args_replacer(args, data):
5555
return ["y"]
5656
elif len(args) == 2:
5757
# this can be two cases: x,y or y,c
58-
if not args[1] in data:
59-
# this is not in data, so just assume that it is something which
60-
# will not get replaced (color spec or array like).
61-
return ["y", "c"]
6258
# it's data, but could be a color code like 'ro' or 'b--'
6359
# -> warn the user in that case...
60+
6461
try:
6562
_process_plot_format(args[1])
6663
except ValueError:
6764
pass
6865
else:
69-
warnings.warn(
70-
"Second argument {!r} is ambiguous: could be a color spec but "
71-
"is in data; using as data. Either rename the entry in data "
72-
"or use three arguments to plot.".format(args[1]),
73-
RuntimeWarning, stacklevel=3)
66+
# arg can be parsed into colour; verify arg is not data
67+
if not args[1] in data:
68+
return ["y", "c"]
69+
else:
70+
warnings.warn(
71+
"Second argument {!r} is ambiguous: could be a color spec but "
72+
"is in data; using as data. Either rename the entry in data "
73+
"or use three arguments to plot.".format(args[1]),
74+
RuntimeWarning, stacklevel=3)
75+
7476
return ["x", "y"]
7577
elif len(args) == 3:
7678
return ["x", "y", "c"]

lib/matplotlib/tests/test_axes.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,15 @@ def test_shaped_data():
584584
plt.plot(xdata[:, 1], xdata[1, :], 'o')
585585

586586

587+
def test_structured_data():
588+
# support for stuctured data
589+
pts = np.array([(1, 1), (2, 2)], dtype=[("ones", float), ("twos", float)])
590+
591+
fig, ax = plt.subplots(2)
592+
ax[0].plot("ones", "twos", data=pts)
593+
ax[1].plot("ones", "twos", "r", data=pts)
594+
595+
587596
@image_comparison(baseline_images=['const_xy'])
588597
def test_const_xy():
589598
fig = plt.figure()

0 commit comments

Comments
 (0)