8000 Merge pull request #23232 from timhoffm/stem-fmt · matplotlib/matplotlib@3e9f0b8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3e9f0b8

Browse files
authored
Merge pull request #23232 from timhoffm/stem-fmt
API: Fix passing stem markerfmt positionally when locs are not given
2 parents 0fe4b08 + 0715480 commit 3e9f0b8

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Passing *linefmt* positionally is undeprecated
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
4+
Positional use of all formatting parameters in `~.Axes.stem` has been
5+
deprecated since Matplotlib 3.5. This deprecation is relaxed so that one can
6+
still pass *linefmt* positionally, i.e. ``stem(x, y, 'r')``.

lib/matplotlib/axes/_axes.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2901,12 +2901,15 @@ def stem(self, *args, linefmt=None, markerfmt=None, basefmt=None, bottom=0,
29012901
heads, = args
29022902
locs = np.arange(len(heads))
29032903
args = ()
2904+
elif isinstance(args[1], str):
2905+
heads, *args = args
2906+
locs = np.arange(len(heads))
29042907
else:
29052908
locs, heads, *args = args
2906-
if args:
2909+
if len(args) > 1:
29072910
_api.warn_deprecated(
29082911
"3.5",
2909-
message="Passing the linefmt parameter positionally is "
2912+
message="Passing the markerfmt parameter positionally is "
29102913 8000
"deprecated since Matplotlib %(since)s; the "
29112914
"parameter will become keyword-only %(removal)s.")
29122915

lib/matplotlib/tests/test_axes.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3833,16 +3833,24 @@ def test_stem(use_line_collection):
38333833

38343834

38353835
def test_stem_args():
3836+
def _assert_equal(stem_container, expected):
3837+
x, y = map(list, stem_container.markerline.get_data())
3838+
assert x == expected[0]
3839+
assert y == expected[1]
3840+
38363841
fig, ax = plt.subplots()
38373842

3838-
x = list(range(10))
3839-
y = list(range(10))
3843+
x = [1, 3, 5]
3844+
y = [9, 8, 7]
38403845

38413846
# Test the call signatures
3842-
ax.stem(y)
3843-
ax.stem(x, y)
3844-
ax.stem(x, y, linefmt='r--')
3845-
ax.stem(x, y, linefmt='r--', basefmt='b--')
3847+
_assert_equal(ax.stem(y), expected=([0, 1, 2], y))
3848+
_assert_equal(ax.stem(x, y), expected=(x, y))
3849+
_assert_equal(ax.stem(x, y, linefmt='r--'), expected=(x, y))
3850+
_assert_equal(ax.stem(x, y, 'r--'), expected=(x, y))
3851+
_assert_equal(ax.stem(x, y, linefmt='r--', basefmt='b--'), expected=(x, y))
3852+
_assert_equal(ax.stem(y, linefmt='r--'), expected=([0, 1, 2], y))
3853+
_assert_equal(ax.stem(y, 'r--'), expected=([0, 1, 2], y))
38463854

38473855

38483856
def test_stem_dates():

0 commit comments

Comments
 (0)
0