Skip to content

Cleanup stem docs and simplify implementation. #18937

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
merged 1 commit into from
Nov 14, 2020
Merged
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
32 changes: 11 additions & 21 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2614,8 +2614,7 @@ def stem(self, *args, linefmt=None, markerfmt=None, basefmt=None, bottom=0,
For horizontal stem plots, the x-values of the stem heads.

linefmt : str, optional
A string defining the properties of the vertical lines. Usually,
this will be a color or a color and a linestyle:
A string defining the color and/or linestyle of the vertical lines:

========= =============
Character Line Style
Expand All @@ -2629,15 +2628,14 @@ def stem(self, *args, linefmt=None, markerfmt=None, basefmt=None, bottom=0,
Default: 'C0-', i.e. solid line with the first color of the color
cycle.

Note: While it is technically possible to specify valid formats
other than color or color and linestyle (e.g. 'rx' or '-.'), this
is beyond the intention of the method and will most likely not
result in a reasonable plot.
Note: Markers specified through this parameter (e.g. 'x') will be
silently ignored (unless using ``use_line_collection=False``).
Instead, markers should be specified using *markerfmt*.

markerfmt : str, optional
A string defining the properties of the markers at the stem heads.
Default: 'C0o', i.e. filled circles with the first color of the
color cycle.
A string defining the color and/or shape of the markers at the stem
heads. Default: 'C0o', i.e. filled circles with the first color of
the color cycle.

basefmt : str, default: 'C3-' ('C2-' in classic mode)
A format string defining the properties of the baseline.
Expand Down Expand Up @@ -2738,20 +2736,12 @@ def stem(self, *args, linefmt=None, markerfmt=None, basefmt=None, bottom=0,

# New behaviour in 3.1 is to use a LineCollection for the stemlines
if use_line_collection:
if orientation == 'horizontal':
stemlines = [
((bottom, loc), (head, loc))
for loc, head in zip(locs, heads)]
else:
stemlines = [
((loc, bottom), (loc, head))
for loc, head in zip(locs, heads)]
if linestyle is None:
linestyle = rcParams['lines.linestyle']
stemlines = mcoll.LineCollection(stemlines, linestyles=linestyle,
colors=linecolor,
label='_nolegend_')
self.add_collection(stemlines)
xlines = self.vlines if orientation == "vertical" else self.hlines
stemlines = xlines(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to be sure:

            self.update_datalim(corners)
            self._request_autoscale_view()

used in xlines does not have any unintended side-effect?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are always going to plot the markers and the baseline, which necessarily bracket the stemlines, so the autolims set by the markers and baseline will be as big as those set by the stemlines anyways.

locs, bottom, heads,
colors=linecolor, linestyles=linestyle, label="_nolegend_")
# Old behaviour is to plot each of the lines individually
else:
stemlines = []
Expand Down