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

Skip to content

Commit a32934c

Browse 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

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

lib/matplotlib/axes/_base.py

Lines 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

Lines 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)