Skip to content

Improve timeline example.#28014

Merged
jklymak merged 1 commit intomatplotlib:mainfrom
anntzer:tl
Apr 4, 2024
Merged

Improve timeline example.#28014
jklymak merged 1 commit intomatplotlib:mainfrom
anntzer:tl

Conversation

@anntzer
Copy link
Copy Markdown
Contributor

@anntzer anntzer commented Apr 3, 2024

  • 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

@github-actions github-actions bot added the Documentation: examples files in galleries/examples label Apr 3, 2024
@timhoffm
Copy link
Copy Markdown
Member

timhoffm commented Apr 3, 2024

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.

@jklymak
Copy link
Copy Markdown
Member

jklymak commented Apr 3, 2024

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.

@timhoffm
Copy link
Copy Markdown
Member

timhoffm commented Apr 3, 2024

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). 😀

@story645
Copy link
Copy Markdown
Member

story645 commented Apr 3, 2024

Probably in the future works bin, but this could be a nice example to show off a scroll widget 😅

@anntzer
Copy link
Copy Markdown
Contributor Author

anntzer commented Apr 3, 2024

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).

@timhoffm
Copy link
Copy Markdown
Member

timhoffm commented Apr 3, 2024

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()

image

We still have a bit of overlap, but I like the grouping by minor releases.

@anntzer
Copy link
Copy Markdown
Contributor Author

anntzer commented Apr 3, 2024

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".

@timhoffm
Copy link
Copy Markdown
Member

timhoffm commented Apr 4, 2024

Feel free to take and modify my code.

@anntzer
Copy link
Copy Markdown
Contributor Author

anntzer commented Apr 4, 2024

Done. Thanks again :)
tl

@jklymak
Copy link
Copy Markdown
Member

jklymak commented Apr 4, 2024

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.

@anntzer
Copy link
Copy Markdown
Contributor Author

anntzer commented Apr 4, 2024

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.
@jklymak jklymak merged commit 394b80d into matplotlib:main Apr 4, 2024
@anntzer anntzer deleted the tl branch April 4, 2024 16:36
@QuLogic QuLogic added this to the v3.9.0 milestone Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Documentation: examples files in galleries/examples Documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants