Bubble plot


A bubble plot is a scatterplot where the circle size is mapped to the value of a third numeric variable. This section shows many bubble plots made with Python, using both the Matplotlib and Seaborn libraries.

⏱ Quick start

The scatterplot() function of seaborn also allows to build bubble charts. Indeed, it has a size parameter that controls circle size according to a numeric variable of the dataset.🔥

# libraries
import matplotlib.pyplot as plt
import seaborn as sns
from gapminder import gapminder # data set

# data
data = gapminder.loc[gapminder.year == 2007]

# use the scatterplot function to build the bubble map
sns.scatterplot(data=data, x="gdpPercap", y="lifeExp", size="pop", legend=False, sizes=(20, 2000))

# show the graph
plt.show()

Seaborn logoBubble plot with Seaborn

Seaborn is the best tool to quickly build a quality bubble chart. The example below are based on the famous gapminder dataset that shows the relationship between gdp per capita, life expectancy and population of world countries.

The examples below start simple by calling the scatterplot() function with the minimum set of parameters. It then show how to change bubble colors to represent a fourth variable, improve general styling, tweak the legend and more.

Matplotlib logoBubble plot with Matplotlib

As for scatterplots, Matplotlib will help us build a bubble plot thanks to the the plt.scatter() function. This function provides a s parameter allowing to pass a third variable that will be mapped to the markers size.

Note that it is a common practice to map a fourth variable to the markers colors thanks to the c parameter. This way, you're now looking a 4 variables in the same time, on the same chart 🎉.

Contact

👋 This document is a work by Yan Holtz. Any feedback is highly encouraged. You can fill an issue on Github, drop me a message onTwitter, or send an email pasting yan.holtz.data with gmail.com.

Violin

Density

Histogram

Boxplot

Ridgeline

Scatterplot

Heatmap

Correlogram

Bubble

Connected Scatter

2D Density

Barplot

Spider / Radar

Wordcloud

Parallel

Lollipop

Circular Barplot

Treemap

Venn Diagram

Donut

Pie Chart

Dendrogram

Circular Packing

Line chart

Area chart

Stacked Area

Streamgraph

Map

Choropleth

Hexbin

Cartogram

Connection

Bubble

Chord Diagram

Network

Sankey

Arc Diagram

Edge Bundling

Colors

Interactivity

Animation with python

Animation

Cheat sheets

Caveats

3D