Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix dicts unpacking for.plot#17506

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
tacaswell merged 5 commits intomatplotlib:masterfromstory645:fix-dicts
May 25, 2020
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletionlib/matplotlib/axes/_base.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -217,7 +217,9 @@ def __call__(self, *args, data=None, **kwargs):
if not args:
return

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

# Repeatedly grab (x, y) or (x, y, format) from the front of args and
# massage them into arguments to plot() or fill().

while args:
this, args = args[:2], args[2:]
if args and isinstance(args[0], str):
Expand Down
37 changes: 36 additions & 1 deletionlib/matplotlib/tests/test_preprocess_data.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,7 +4,8 @@
import pytest

from matplotlib import _preprocess_data

from matplotlib.axes import Axes
from matplotlib.testing.decorators import check_figures_equal

# Notes on testing the plotting functions itself
# * the individual decorated plotting functions are tested in 'test_axes.py'
Expand DownExpand Up@@ -73,6 +74,14 @@ def test_function_call_without_data(func):
"x: ['x'], y: ['y'], ls: x, w: xyz, label: text")


@pytest.mark.parametrize('func', all_funcs, ids=all_func_ids)
def test_function_call_with_dict_input(func):
"""Tests with dict input, unpacking via preprocess_pipeline"""
data = {'a': 1, 'b': 2}
assert(func(None, data.keys(), data.values()) ==
"x: ['a', 'b'], y: [1, 2], ls: x, w: xyz, label: None")


@pytest.mark.parametrize('func', all_funcs, ids=all_func_ids)
def test_function_call_with_dict_data(func):
"""Test with dict data -> label comes from the value of 'x' parameter."""
Expand DownExpand Up@@ -215,3 +224,29 @@ def funcy(ax, x, y, z, t=None):
assert not re.search(r"every other argument", funcy.__doc__)
assert not re.search(r"the following arguments .*: \*x\*, \*t\*\.",
funcy.__doc__)


class TestPlotTypes:

plotters = [Axes.scatter, Axes.bar, Axes.plot]

@pytest.mark.parametrize('plotter', plotters)
@check_figures_equal(extensions=['png'])
def test_dict_unpack(self, plotter, fig_test, fig_ref):
x = [1, 2, 3]
y = [4, 5, 6]
ddict = dict(zip(x, y))

plotter(fig_test.subplots(),
ddict.keys(), ddict.values())
plotter(fig_ref.subplots(), x, y)

@pytest.mark.parametrize('plotter', plotters)
@check_figures_equal(extensions=['png'])
def test_data_kwarg(self, plotter, fig_test, fig_ref):
x = [1, 2, 3]
y = [4, 5, 6]

plotter(fig_test.subplots(), 'xval', 'yval',
data={'xval': x, 'yval': y})
plotter(fig_ref.subplots(), x, y)

[8]ページ先頭

©2009-2025 Movatter.jp