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

Appearance settings

Commit a32934c

Browse filesBrowse files
committed
plt.plot(x, y, fmt) allows to specify marker, linestyle and color via
`fmt`. Warn if there are additionally keyword arguments that specify the same properties. Closes #19275. Builds on top of #19277, which cleans up _plot_args(). This separation is done for easier review of the cleanup.
1 parent acdfe3f commit a32934c
Copy full SHA for a32934c

File tree

Expand file treeCollapse file tree

2 files changed

+16
-0
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+16
-0
lines changed

‎lib/matplotlib/axes/_base.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_base.py
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,12 @@ def _plot_args(self, tup, kwargs, return_kwargs=False):
461461
for prop_name, val in zip(('linestyle', 'marker', 'color'),
462462
(linestyle, marker, color)):
463463
if val is not None:
464+
if prop_name in kwargs:
465+
_api.warn_external(
466+
f"{prop_name} is redundantly defined by the "
467+
f"'{prop_name}' keyword argument and the fmt sting "
468+
f'("{fmt}"). The keyword argument will take '
469+
"precedence.")
464470
kw[prop_name] = val
465471

466472
if len(xy) == 2:

‎lib/matplotlib/tests/test_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_axes.py
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,16 @@ def test_fill_units():
624624
fig.autofmt_xdate()
625625

626626

627+
@pytest.mark.xfail('Warning not yet activated.')
628+
def test_plot_format_kwarg_redundant():
629+
with pytest.warns(UserWarning, match="marker .* redundantly defined"):
630+
plt.plot([0], [0], 'o', marker='x')
631+
with pytest.warns(UserWarning, match="linestyle .* redundantly defined"):
632+
plt.plot([0], [0], '-', linestyle='--')
633+
with pytest.warns(UserWarning, match="color .* redundantly defined"):
634+
plt.plot([0], [0], 'r', color='blue')
635+
636+
627637
@image_comparison(['single_point', 'single_point'])
628638
def test_single_point():
629639
# Issue #1796: don't let lines.marker affect the grid

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.