Skip to content

Commit 85a96fb

Browse files
authored
Merge pull request #16474 from anntzer/ulc
Switch default of stem(use_line_collection=...) to True.
2 parents c91d7ef + a75c716 commit 85a96fb

File tree

7 files changed

+23
-42
lines changed

7 files changed

+23
-42
lines changed

doc/api/next_api_changes/behaviour.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,10 @@ of *y*, the second column of *x* against the second column of *y*, **and** the
7171
first column of *x* against the third column of *y*. This now raises an error
7272
instead.
7373

74-
`.Text.update_from` now copies usetex state from the source Text
74+
`.Text.update_from` now copies usetex state from the source Text
7575
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
76+
77+
`~.Axes.stem` now defaults to ``use_line_collection=True``
78+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
79+
This creates the stem plot as a `.LineCollection` rather than individual
80+
`.Line2D` objects, greatly improving performance.

examples/lines_bars_and_markers/stem_plot.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
x = np.linspace(0.1, 2 * np.pi, 41)
1313
y = np.exp(np.sin(x))
1414

15-
plt.stem(x, y, use_line_collection=True)
15+
plt.stem(x, y)
1616
plt.show()
1717

1818
#############################################################################
@@ -24,7 +24,7 @@
2424
# control adapt the line objects returned by `~.pyplot`.
2525

2626
markerline, stemlines, baseline = plt.stem(
27-
x, y, linefmt='grey', markerfmt='D', bottom=1.1, use_line_collection=True)
27+
x, y, linefmt='grey', markerfmt='D', bottom=1.1)
2828
markerline.set_markerfacecolor('none')
2929
plt.show()
3030

examples/lines_bars_and_markers/timeline.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@
7272
ax.set(title="Matplotlib release dates")
7373

7474
markerline, stemline, baseline = ax.stem(dates, levels,
75-
linefmt="C3-", basefmt="k-",
76-
use_line_collection=True)
75+
linefmt="C3-", basefmt="k-")
7776

7877
plt.setp(markerline, mec="k", mfc="w", zorder=3)
7978

lib/matplotlib/axes/_axes.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2652,7 +2652,7 @@ def broken_barh(self, xranges, yrange, **kwargs):
26522652

26532653
@_preprocess_data()
26542654
def stem(self, *args, linefmt=None, markerfmt=None, basefmt=None, bottom=0,
2655-
label=None, use_line_collection=False):
2655+
label=None, use_line_collection=True):
26562656
"""
26572657
Create a stem plot.
26582658
@@ -2709,12 +2709,12 @@ def stem(self, *args, linefmt=None, markerfmt=None, basefmt=None, bottom=0,
27092709
label : str, default: None
27102710
The label to use for the stems in legends.
27112711
2712-
use_line_collection : bool, default: False
2712+
use_line_collection : bool, default: True
27132713
If ``True``, store and plot the stem lines as a
2714-
`~.collections.LineCollection` instead of individual lines. This
2715-
significantly increases performance, and will become the default
2716-
option in Matplotlib 3.3. If ``False``, defaults to the old
2717-
behavior of using a list of `.Line2D` objects.
2714+
`~.collections.LineCollection` instead of individual lines, which
2715+
significantly increases performance. If ``False``, defaults to the
2716+
old behavior of using a list of `.Line2D` objects. This parameter
2717+
may be deprecated in the future.
27182718
27192719
Returns
27202720
-------
@@ -2802,12 +2802,6 @@ def stem(self, *args, linefmt=None, markerfmt=None, basefmt=None, bottom=0,
28022802
self.add_collection(stemlines)
28032803
# Old behaviour is to plot each of the lines individually
28042804
else:
2805-
cbook._warn_external(
2806-
'In Matplotlib 3.3 individual lines on a stem plot will be '
2807-
'added as a LineCollection instead of individual lines. '
2808-
'This significantly improves the performance of a stem plot. '
2809-
'To remove this warning and switch to the new behaviour, '
2810-
'set the "use_line_collection" keyword argument to True.')
28112805
stemlines = []
28122806
for xi, yi in zip(x, y):
28132807
l, = self.plot([xi, xi], [bottom, yi],

lib/matplotlib/pyplot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2735,7 +2735,7 @@ def stackplot(
27352735
@docstring.copy(Axes.stem)
27362736
def stem(
27372737
*args, linefmt=None, markerfmt=None, basefmt=None, bottom=0,
2738-
label=None, use_line_collection=False, data=None):
2738+
label=None, use_line_collection=True, data=None):
27392739
return gca().stem(
27402740
*args, linefmt=linefmt, markerfmt=markerfmt, basefmt=basefmt,
27412741
bottom=bottom, label=label,

lib/matplotlib/tests/test_axes.py

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3341,28 +3341,11 @@ def test_stem(use_line_collection):
33413341
label=' ', use_line_collection=use_line_collection)
33423342

33433343
fig, ax = plt.subplots()
3344-
if use_line_collection:
3345-
ax.stem(*args, **kwargs)
3346-
else:
3347-
with pytest.warns(UserWarning):
3348-
ax.stem(*args, **kwargs)
3344+
ax.stem(*args, **kwargs)
33493345

33503346
ax.legend()
33513347

33523348

3353-
@check_figures_equal(extensions=['png'])
3354-
def test_stem_params(fig_test, fig_ref):
3355-
x = np.linspace(0, 3.14, 37)
3356-
y = np.sin(x)
3357-
3358-
ax = fig_test.subplots()
3359-
ax.stem(x, y, linefmt='grey', use_line_collection=True)
3360-
3361-
ax = fig_ref.subplots()
3362-
with pytest.warns(UserWarning):
3363-
ax.stem(x, y, linefmt='grey')
3364-
3365-
33663349
def test_stem_args():
33673350
fig = plt.figure()
33683351
ax = fig.add_subplot(1, 1, 1)
@@ -3371,18 +3354,18 @@ def test_stem_args():
33713354
y = list(range(10))
33723355

33733356
# Test the call signatures
3374-
ax.stem(y, use_line_collection=True)
3375-
ax.stem(x, y, use_line_collection=True)
3376-
ax.stem(x, y, 'r--', use_line_collection=True)
3377-
ax.stem(x, y, 'r--', basefmt='b--', use_line_collection=True)
3357+
ax.stem(y)
3358+
ax.stem(x, y)
3359+
ax.stem(x, y, 'r--')
3360+
ax.stem(x, y, 'r--', basefmt='b--')
33783361

33793362

33803363
def test_stem_dates():
33813364
fig, ax = plt.subplots(1, 1)
33823365
xs = [dateutil.parser.parse("2013-9-28 11:00:00"),
33833366
dateutil.parser.parse("2013-9-28 12:00:00")]
33843367
ys = [100, 200]
3385-
ax.stem(xs, ys, "*-", use_line_collection=True)
3368+
ax.stem(xs, ys, "*-")
33863369

33873370

33883371
@image_comparison(['hist_stacked_stepfilled_alpha'])

lib/matplotlib/tests/test_container.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
def test_stem_remove():
55
ax = plt.gca()
6-
st = ax.stem([1, 2], [1, 2], use_line_collection=True)
6+
st = ax.stem([1, 2], [1, 2])
77
st.remove()
88

99

0 commit comments

Comments
 (0)