A beeswarm plot or swarmplot is a type of data visualization that displays individual data points in a way that they don't overlap, resulting in a "swarming" effect that resembles a swarm of bees.

This chart type helps in revealing the distribution of the data along a numeric variable, highlighting the density and variation of the data more effectively than traditional scatter plots or box plots.

This section provides many beeswarm chart examples made with Python, using seaborn or matplotlib. Examples cover the most common use-cases, but also show how far in term of customization it is possible to go.

🤔 When to use a beeswarm chart?

The beeswarm chart is a very good alternative to the boxplot that hides the underlying dataset.

However, do not try to use it with a very big dataset. Indeed, avoiding circle overlap will be possible with a small amount of data points, but it will get impossible otherwise. In this case, take a look to the violin chart instead.

To read more about this, visit data-to-viz.com that has a dedicated article.

Seaborn logoBeeswarm with Seaborn

Seaborn is a python library allowing to make better charts easily. The swarmplot() function should get you started in minutes. The examples below aim at showcasing the various possibilities this function offers.

Matplotlib logoBeeswarm with Matplotlib

Building a beeswarm plot with matplotlib requires more manual work since no built-in function exists for the job.

The following blog-post explains how to build yours from scratch. The function divides the data into bins, calculates the upper bounds for each bin, and then arranges the data points in each bin to create the horizontal spread in the plot, ensuring they don't overlap.

Once the dot position is available, it is possible to render it usingmatplotlib:


👋 This document is a work by Yan Holtz. You can contribute on github, send me a feedback on twitter or subscribe to the newsletter to know when new examples are published! 🔥