-
-
Notifications
You must be signed in to change notification settings - Fork 8k
Improve timeline example. #28014
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve timeline example. #28014
Conversation
I kind of liked the horizontal layout because time is often on the horizontal axis. Can we still get away with that? (If not I also won't block).
The sorting by release date should already decrease overlap of lines and labels a lot. Then, left-align the labels to the bars. You could add a semi-transparent white background to the text to make the overlap less visually distracting.
Additional suggestion: Fill the minor releases with the red line color to make them stand out also on the axis.
I would go further and use a smaller font for point releases, and maybe try and have the minor releases always to the far left or far right?
For the one or two releases with visual overlap, I'd actually nudge them manually. Or we could use this as an excuse to show an automated un-overlapping algorithm.
Or we could use this as an excuse to show an automated un-overlapping algorithm.
Let's not stray too far from the main topic. If you want to show an un-overlapping algorithm, that's worth an example of its own (e.g. add annotations to scatter points). 😀
Probably in the future works bin, but this could be a nice example to show off a scroll widget 😅
A native scroller (probably not a matplotlib scroll widget...) is something that @efiring has been arguing for for some time, IIRC (I agree that would be useful).
Alternative suggestion:
def level_from_name(name):
minor = int(name[-3])
bugfix = int(name[-1])
h = 1 + 0.8 * (5-bugfix)
return h if minor % 2 == 0 else -h
levels = [level_from_name(name) for name in names]
# Create figure and plot a stem plot with the date
fig, ax = plt.subplots(figsize=(8.8, 4), layout="constrained")
ax.set(title="Matplotlib release dates")
ax.vlines(dates, 0, levels,
color=[("tab:red", 1 if name.endswith(".0") else .5) for name in names])) # The vertical stems.
ax.plot(dates, np.zeros_like(dates), "-", color="black") # baseline
minor_dates = [date for date, name in zip(dates, names) if name[-1] == '0']
bugfix_dates = [date for date, name in zip(dates, names) if name[-1] != '0']
ax.plot(bugfix_dates, np.zeros_like(bugfix_dates), "ko", mfc="white")
ax.plot(minor_dates, np.zeros_like(minor_dates), "ko", mfc="tab:red")
# annotate lines
for d, l, r in zip(dates, levels, names):
ax.annotate(r, xy=(d, l),
xytext=(-3, np.sign(l)*3), textcoords="offset points",
verticalalignment="bottom" if l > 0 else "top",
bbox=dict(boxstyle='square', pad=0, lw=0, fc=(1, 1, 1, 0.7)))
ax.yaxis.set(major_locator=mdates.YearLocator(),
major_formatter=mdates.DateFormatter("%Y"))
# remove y-axis and spines
ax.yaxis.set_visible(False)
ax.spines[["left", "top", "right"]].set_visible(False)
ax.margins(y=0.1)
plt.show()
We still have a bit of overlap, but I like the grouping by minor releases.
Yes, that looks way better. I would have put 3.0.0 on the opposite side of 2.2.0, though? so not "minor % 2" but more like "index into the list of major.minor releases (ignoring micro) and get that index %2".
Feel free to take and modify my code.
Done. Thanks again :)
tl
This looks good. As minor nits - I'd drop "v" from each label as very redundant. I'd also make the version labels a different font from the dates either size, italics, or both. But feel free to self merge if you don't agree w those suggestions.
Removing the v looks good. I think just making the major releases in bold is enough (the minor releases are never close to the xaxis so they don't get confused with the dates).
tl
- Make the timeline vertical, which avoids many overlaps between labels and lines. - Sort releases by dates, so that the oldest release starts with a long stemline rather than some random length depending on how many releases there are. - Make minor releases fainter, which improves the hierarchical impression. - Switch to yearly date labels, which are enough for this timeline.
Old figure:
oldtl
New figure:
tl
Further improvements left as "future work" :-)
PR summary
PR checklist