Skip to content

Commit 80b30af

Browse files
authored
Merge pull request #21159 from meeseeksmachine/auto-backport-of-pr-21127-on-v3.5.x
Backport PR #21127 on branch v3.5.x (Simplify argument parsing in stem().)
2 parents ce88c78 + 78bc173 commit 80b30af

File tree

1 file changed

+8
-40
lines changed

1 file changed

+8
-40
lines changed

lib/matplotlib/axes/_axes.py

+8-40
Original file line numberDiff line numberDiff line change
@@ -2881,50 +2881,18 @@ def stem(self, *args, linefmt=None, markerfmt=None, basefmt=None, bottom=0,
28812881

28822882
# defaults for formats
28832883
if linefmt is None:
2884-
try:
2885-
# fallback to positional argument
2886-
linefmt = args[0]
2887-
except IndexError:
2888-
linecolor = 'C0'
2889-
linemarker = 'None'
2890-
linestyle = '-'
2891-
else:
2892-
linestyle, linemarker, linecolor = \
2893-
_process_plot_format(linefmt)
2894-
else:
2895-
linestyle, linemarker, linecolor = _process_plot_format(linefmt)
2884+
linefmt = args[0] if len(args) > 0 else "C0-"
2885+
linestyle, linemarker, linecolor = _process_plot_format(linefmt)
28962886

28972887
if markerfmt is None:
2898-
try:
2899-
# fallback to positional argument
2900-
markerfmt = args[1]
2901-
except IndexError:
2902-
markercolor = 'C0'
2903-
markermarker = 'o'
2904-
markerstyle = 'None'
2905-
else:
2906-
markerstyle, markermarker, markercolor = \
2907-
_process_plot_format(markerfmt)
2908-
else:
2909-
markerstyle, markermarker, markercolor = \
2910-
_process_plot_format(markerfmt)
2888+
markerfmt = args[1] if len(args) > 1 else "C0o"
2889+
markerstyle, markermarker, markercolor = \
2890+
_process_plot_format(markerfmt)
29112891

29122892
if basefmt is None:
2913-
try:
2914-
# fallback to positional argument
2915-
basefmt = args[2]
2916-
except IndexError:
2917-
if rcParams['_internal.classic_mode']:
2918-
basecolor = 'C2'
2919-
else:
2920-
basecolor = 'C3'
2921-
basemarker = 'None'
2922-
basestyle = '-'
2923-
else:
2924-
basestyle, basemarker, basecolor = \
2925-
_process_plot_format(basefmt)
2926-
else:
2927-
basestyle, basemarker, basecolor = _process_plot_format(basefmt)
2893+
basefmt = (args[2] if len(args) > 2 else
2894+
"C2-" if rcParams["_internal.classic_mode"] else "C3-")
2895+
basestyle, basemarker, basecolor = _process_plot_format(basefmt)
29282896

29292897
# New behaviour in 3.1 is to use a LineCollection for the stemlines
29302898
if use_line_collection:

0 commit comments

Comments
 (0)