|
53 | 53 | dates = [datetime.strptime(d, "%Y-%m-%d") for d in dates] |
54 | 54 |
|
55 | 55 | ############################################################################## |
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 | +# |
60 | 60 | # For each event, we add a text label via `~.Axes.annotate`, which is offset |
61 | 61 | # in units of points from the tip of the event line. |
62 | 62 | # |
|
71 | 71 | fig, ax = plt.subplots(figsize=(8.8, 4), constrained_layout=True) |
72 | 72 | ax.set(title="Matplotlib release dates") |
73 | 73 |
|
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. |
81 | 77 |
|
82 | 78 | # annotate lines |
83 | 79 | for d, l, r in zip(dates, levels, names): |
|
111 | 107 | # in this example: |
112 | 108 |
|
113 | 109 | import matplotlib |
114 | | -matplotlib.axes.Axes.stem |
115 | 110 | matplotlib.axes.Axes.annotate |
| 111 | +matplotlib.axes.Axes.vlines |
116 | 112 | matplotlib.axis.Axis.set_major_locator |
117 | 113 | matplotlib.axis.Axis.set_major_formatter |
118 | 114 | matplotlib.dates.MonthLocator |
|
0 commit comments