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

Skip to content

Commit 2e20e67

Browse files
committed
closes matplotlib#17502 by adding check to plot
1 parent e92682d commit 2e20e67

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,9 @@ def __call__(self, *args, data=None, **kwargs):
217217
if not args:
218218
return
219219

220-
if data is not None: # Process the 'data' kwarg.
220+
if data is None: # Process dict views
221+
args = [cbook.sanitize_sequence(a) for a in args]
222+
else: # Process the 'data' kwarg.
221223
replaced = [mpl._replacer(data, arg) for arg in args]
222224
if len(args) == 1:
223225
label_namer_idx = 0
@@ -262,6 +264,7 @@ def __call__(self, *args, data=None, **kwargs):
262264

263265
# Repeatedly grab (x, y) or (x, y, format) from the front of args and
264266
# massage them into arguments to plot() or fill().
267+
265268
while args:
266269
this, args = args[:2], args[2:]
267270
if args and isinstance(args[0], str):

lib/matplotlib/tests/test_preprocess_data.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,13 @@ def test_function_call_without_data(func):
7373
assert (func(None, x="x", y="y", label="text") ==
7474
"x: ['x'], y: ['y'], ls: x, w: xyz, label: text")
7575

76+
7677
@pytest.mark.parametrize('func', all_funcs, ids=all_func_ids)
7778
def test_function_call_with_dict_input(func):
7879
"""Tests with dict input, unpacking via preprocess_pipeline"""
79-
data = {'a': 1, 'b': 2}
80+
data = {'a': 1, 'b': 2}
8081
assert(func(None, data.keys(), data.values()) ==
81-
"x: ['a', 'b'], y: [1, 2], ls: x, w: xyz, label: None")
82+
"x: ['a', 'b'], y: [1, 2], ls: x, w: xyz, label: None")
8283

8384

8485
@pytest.mark.parametrize('func', all_funcs, ids=all_func_ids)
@@ -227,25 +228,23 @@ def funcy(ax, x, y, z, t=None):
227228

228229
class TestPlotTypes:
229230
plotters = [Axes.scatter, Axes.bar, Axes.plot]
230-
231231
@pytest.mark.parametrize('plotter', plotters)
232232
@check_figures_equal(extensions=['png'])
233233
def test_dict_unpack(self, plotter, fig_test, fig_ref):
234-
x = [1,2,3]
235-
y = [4,5,6]
236-
ddict = dict(zip(x,y))
234+
x = [1, 2, 3]
235+
y = [4, 5, 6]
236+
ddict = dict(zip(x, y))
237237

238-
plotter(fig_test.subplots(),
238+
plotter(fig_test.subplots(),
239239
ddict.keys(), ddict.values())
240240
plotter(fig_ref.subplots(), x, y)
241241

242242
@pytest.mark.parametrize('plotter', plotters)
243243
@check_figures_equal(extensions=['png'])
244244
def test_data_kwarg(self, plotter, fig_test, fig_ref):
245-
x = [1,2,3]
246-
y = [4,5,6]
245+
x = [1, 2, 3]
246+
y = [4, 5, 6]
247247

248-
plotter(fig_test.subplots(), 'xval', 'yval',
249-
data={'xval':x, 'yval':y})
250-
plotter(fig_ref.subplots(), x, y)
251-
248+
plotter(fig_test.subplots(), 'xval', 'yval',
249+
data={'xval': x, 'yval': y})
250+
plotter(fig_ref.subplots(), x, y)

0 commit comments

Comments
 (0)