Hey everyone –
I’ve started working on one of Plotly’s oldest issues: text autoposition on scatter plots.
If you display text on a scatter plot or a line plot, you can easily end up with a situation where the text on the points overlaps each other. It’s a huge pain; you can either remove some labels, attempt to individually modify the position of each text element, or add your own text annotations one at a time.
I’ve been exploring ways to make the text positioning automatic. It’ll try one of the 8 positions right next to a point, and if none are available, then try it one level further away from the point, and so on.
It’ll also prioritize placing text in a direction that’s “away” from the nearby points, to make room for text being laid out by neighbors in the future.
There are still cases where the points will be too crowded to show all of the text and in these cases the text will be hidden. You can control which text is displayed by setting a textpriority vector: set e.g. 1 on the points you really want displayed (e.g. local minima/maxima, or points you’re trying to highlight) and 0 for ones you don’t. Any numbers work here, and the priority can be on a scale, too.
Here’s a before / after chart that inspired me to work on this feature in the first place. A little side research project showing which conditions get studied/funded vs % of ppl that are affected by the condition. Made for a close friend of mine who is navigating the painful, poorly-studied world of endometriosis.
Before:
After:
And some of the test cases I’m considering:
It recomputes on zooming and panning, too:

Feedback welcome! You can give it a try in PR #8065. This is still in the R&D phase right now, so very much subject to change as we get through review.


