Matplotlib: Change Scatter Plot Marker Size
Introduction
Matplotlib is one of the most widely used data visualization libraries in Python. Much of Matplotlib’s popularity comes from its customization options – you can tweak just about any element from its hierarchy of objects.
In this tutorial, we’ll take a look at how to change the marker size in a Matplotlib scatter plot.
Import Data
We’ll use the World Happiness dataset, and compare the Happiness Score against varying features to see what influences perceived happiness in the world:
import pandas as pd
df = pd.read_csv('worldHappiness2019.csv')
Then, we can easily manipulate the size of the markers used to represent entries in this dataset.
Change Marker Size in Matplotlib Scatter Plot
Let’s start off by plotting the generosity score against the GDP per capita:
import matplotlib.pyplot as plt
import pandas as pd
df = pd.read_csv('worldHappiness2019.csv')
fig, ax = plt.subplots(figsize=(10,