Skip to content

Commit d4ba4e7

Browse files
committed
Use vlines() and plot(), not stem(), in timeline example.
It's actually easier (IMO...) to achieve the desired result by combining vlines() and plot() is actually much easier rather than by using stem() and then fiddling with the artists. (The visual result is unchanged.)
1 parent 2699c70 commit d4ba4e7

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

examples/lines_bars_and_markers/timeline.py

Lines changed: 8 additions & 13 deletions
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,14 +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-
use_line_collection=True)
77-
78-
plt.setp(markerline, mec="k", mfc="w", zorder=3)
79-
80-
# Shift the markers to the baseline by replacing the y-data by zeros.
81-
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.
8277

8378
# annotate lines
8479
for d, l, r in zip(dates, levels, names):
@@ -112,8 +107,8 @@
112107
# in this example:
113108

114109
import matplotlib
115-
matplotlib.axes.Axes.stem
116110
matplotlib.axes.Axes.annotate
111+
matplotlib.axes.Axes.vlines
117112
matplotlib.axis.Axis.set_major_locator
118113
matplotlib.axis.Axis.set_major_formatter
119114
matplotlib.dates.MonthLocator

0 commit comments

Comments
 (0)