Skip to content

Commit ae72e62

Browse files
authored
Merge pull request #16475 from anntzer/timeline
Use vlines() and plot(), not stem(), in timeline example.
2 parents 85a96fb + 06e28a6 commit ae72e62

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

examples/lines_bars_and_markers/timeline.py

+8-12
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@
5353
dates = [datetime.strptime(d, "%Y-%m-%d") for d in dates]
5454

5555
##############################################################################
56-
# Next, we'll create a `~.Axes.stem` plot with some variation in levels as to
57-
# distinguish even close-by events. In contrast to a usual stem plot, we will
58-
# shift the markers to the baseline for visual emphasis on the one-dimensional
59-
# nature of the time line.
56+
# Next, we'll create a stem plot with some variation in levels as to
57+
# distinguish even close-by events. We add markers on the baseline for visual
58+
# emphasis on the one-dimensional nature of the time line.
59+
#
6060
# For each event, we add a text label via `~.Axes.annotate`, which is offset
6161
# in units of points from the tip of the event line.
6262
#
@@ -71,13 +71,9 @@
7171
fig, ax = plt.subplots(figsize=(8.8, 4), constrained_layout=True)
7272
ax.set(title="Matplotlib release dates")
7373

74-
markerline, stemline, baseline = ax.stem(dates, levels,
75-
linefmt="C3-", basefmt="k-")
76-
77-
plt.setp(markerline, mec="k", mfc="w", zorder=3)
78-
79-
# Shift the markers to the baseline by replacing the y-data by zeros.
80-
markerline.set_ydata(np.zeros(len(dates)))
74+
ax.vlines(dates, 0, levels, color="tab:red") # The vertical stems.
75+
ax.plot(dates, np.zeros_like(dates), "-o",
76+
color="k", markerfacecolor="w") # Baseline and markers on it.
8177

8278
# annotate lines
8379
for d, l, r in zip(dates, levels, names):
@@ -111,8 +107,8 @@
111107
# in this example:
112108

113109
import matplotlib
114-
matplotlib.axes.Axes.stem
115110
matplotlib.axes.Axes.annotate
111+
matplotlib.axes.Axes.vlines
116112
matplotlib.axis.Axis.set_major_locator
117113
matplotlib.axis.Axis.set_major_formatter
118114
matplotlib.dates.MonthLocator

0 commit comments

Comments
 (0)