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

Skip to content

Backport PR #23232 on branch v3.5.x (Fix passing stem markerfmt positionally when locs are not given) #23292

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions doc/api/next_api_changes/deprecations/23232-TH.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Passing *linefmt* positionally is undeprecated
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Positional use of all formatting parameters in `~.Axes.stem` has been
deprecated since Matplotlib 3.5. This deprecation is relaxed so that one can
still pass *linefmt* positionally, i.e. ``stem(x, y, 'r')``.
7 changes: 5 additions & 2 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2853,12 +2853,15 @@ def stem(self, *args, linefmt=None, markerfmt=None, basefmt=None, bottom=0,
heads, = args
locs = np.arange(len(heads))
args = ()
elif isinstance(args[1], str):
heads, *args = args
locs = np.arange(len(heads))
else:
locs, heads, *args = args
if args:
if len(args) > 1:
_api.warn_deprecated(
"3.5",
message="Passing the linefmt parameter positionally is "
message="Passing the markerfmt parameter positionally is "
"deprecated since Matplotlib %(since)s; the "
"parameter will become keyword-only %(removal)s.")

Expand Down
20 changes: 14 additions & 6 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3703,16 +3703,24 @@ def test_stem(use_line_collection):


def test_stem_args():
def _assert_equal(stem_container, expected):
x, y = map(list, stem_container.markerline.get_data())
assert x == expected[0]
assert y == expected[1]

fig, ax = plt.subplots()

x = list(range(10))
y = list(range(10))
x = [1, 3, 5]
y = [9, 8, 7]

# Test the call signatures
ax.stem(y)
ax.stem(x, y)
ax.stem(x, y, linefmt='r--')
ax.stem(x, y, linefmt='r--', basefmt='b--')
_assert_equal(ax.stem(y), expected=([0, 1, 2], y))
_assert_equal(ax.stem(x, y), expected=(x, y))
_assert_equal(ax.stem(x, y, linefmt='r--'), expected=(x, y))
_assert_equal(ax.stem(x, y, 'r--'), expected=(x, y))
_assert_equal(ax.stem(x, y, linefmt='r--', basefmt='b--'), expected=(x, y))
_assert_equal(ax.stem(y, linefmt='r--'), expected=([0, 1, 2], y))
_assert_equal(ax.stem(y, 'r--'), expected=([0, 1, 2], y))


def test_stem_dates():
Expand Down