1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| levels = np.array([-5, 5, -3, 3, -1, 1]) fig, ax = plt.subplots(figsize=(8, 5))
start = min(dates) stop = max(dates) ax.plot((start, stop), (0, 0), 'k', alpha=.5)
for ii, (iname, idate) in enumerate(zip(names, dates)): level = levels[ii % 6] vert = 'top' if level < 0 else 'bottom'
ax.scatter(idate, 0, s=100, facecolor='w', edgecolor='k', zorder=9999) ax.plot((idate, idate), (0, level), c='r', alpha=.7) ax.text(idate, level, iname, horizontalalignment='right', verticalalignment=vert, fontsize=14, backgroundcolor=(1., 1., 1., .3)) ax.set(title="Matplotlib release dates")
ax.get_xaxis().set_major_locator(mdates.MonthLocator(interval=3)) ax.get_xaxis().set_major_formatter(mdates.DateFormatter("%b %Y")) fig.autofmt_xdate()
plt.setp((ax.get_yticklabels() + ax.get_yticklines() + list(ax.spines.values())), visible=False) plt.show()
|