Skip to content

Commit 5669261

Browse files
authored
Merge pull request #10810 from zhangeugenia/bugfix-for-issue-8818
Fix for plt.plot() does not support structured arrays as data= kwarg
2 parents 51c79c8 + 557ddea commit 5669261

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/matplotlib/axes/_axes.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@ def _plot_args_replacer(args, data):
4949
return ["y"]
5050
elif len(args) == 2:
5151
# this can be two cases: x,y or y,c
52-
if not args[1] in data:
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)):
5357
# this is not in data, so just assume that it is something which
5458
# will not get replaced (color spec or array like).
5559
return ["y", "c"]

lib/matplotlib/tests/test_axes.py

+10
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,16 @@ 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+
# this should not read second name as a format and raise ValueError
592+
fig, ax = plt.subplots(2)
593+
ax[0].plot("ones", "twos", data=pts)
594+
ax[1].plot("ones", "twos", "r", data=pts)
595+
596+
587597
@image_comparison(baseline_images=['const_xy'])
588598
def test_const_xy():
589599
fig = plt.figure()

0 commit comments

Comments
 (0)