โŒ Don't use a legend (do this instead)


๐Ÿ‘‹ Hi!

You're now more than 9000 people reading this newsletter ๐Ÿ˜ฑ. Thank you so much! ๐Ÿ™๐Ÿ™๐Ÿ™
โ€‹
If you want to share it with a friend, I just put together a (for now, ugly) homepage with all past issues.

As always, todayโ€™s tip is short but powerful. Letโ€™s talk aboutโ€ฆ
โ€‹

The problem with legends

Most dataviz libraries make it easy to add legends. That's great! Sometimes, theyโ€™re essential for understanding a chart.

But most of the time? Legends are a hassle.

Take this stacked area chart, for example:
โ€‹
โ€‹

Reading it means constantly jumping back and forth between the chart and the legend. What does this color mean? Check the legend. What about this one? Check again. And again. ๐Ÿ˜ณ

Thatโ€™s a lot of unnecessary cognitive load. Instead of absorbing the story, your audience will struggle just to decode the chart. Youโ€™ll lose their attention.

So hereโ€™s my advice: If you can remove the legend, remove it.

Solution 1: Direct labeling

Instead of using a separate legend, label the groups directly on the chart.

Line charts / Stacked area charts? Place the labels near the end of the lines. Scatterplots? Find a good spot near the groupโ€™s center. Streamgraphs? Position labels inside the flow where they fit naturally.

Here is an example we've built for the Python Graph Gallery:
โ€‹

You see a group, and know instantly what it is! This takes extra effort, but trust me: your readers will thank you.

Technical tip:โ€‹
In R, the
ggrepel package helps position labels without overlap. In Python, check out drawarrow for easy annotation with arrows.

โ€‹
โ€‹
โ€‹Solution 2: Color in the title

That's another solution: use colors in the title to highlight key categories.
โ€‹
This way, you deliver the main message and introduce the groups in one go.
โ€‹
Cedric Scherer uses this technique very often. Here is an example with a dumbbell chart from the r graph gallery:
โ€‹
โ€‹

โ€‹
Takeaway

Whenever possible, ditch the legend to make your chart easier to read.

Still skeptical? Check out Dataviz-inspiration.com. Youโ€™ll notice that most top-tier visualizations use direct annotation, not legends.

Hope this helps and see you next week!

Yan
โ€‹
โ€‹PS: this post is a short abstract from the 3rd module of Matplotlib Journey. We just shipped it, and the course is now almost complete ๐ŸŽ‰
โ€‹
โ€‹PPS: I'm working on a tool allowing to create a homepage like mine in less than 30 minutes. Would you like to beta-test it? Hit reply!
โ€‹

Yan Holtz

โ€‹Find me on X, LinkedIn, or check my Homepageโ€‹

โ€‹

๐Ÿ‘‹ By the way, there are 3 ways I can help you!

  • Consulting: I help my clients design and create interactive dataviz webpages to make their data alive
  • Online Courses: 2000+ ppl already followed my in-depth, interactive learning experiences about R, matplotlib, ggplot2 and d3.jsโ€‹
  • Engaging Talks: I'm deeply passionate about tech and dataviz. Hire me for a talk or a training!

Check yan-holtz.com or hit reply any time!

โ€‹

https://preview.kit-mail3.com/unsubscribeโ€‹
โ€‹Unsubscribe ยท Preferencesโ€‹

background

Subscribe to Dataviz Universe