How to Do a Scatter Plot with Empty Circles in Python
Scatter plots are a powerful visualization tool that helps in identifying relationships between two quantitative variables. In Python, libraries like Matplotlib and Seaborn provide excellent functionalities for creating scatter plots with various customizations. One common customization is to create scatter plots with empty circles. This article will guide us through the steps to create a scatter plot with empty circles using Matplotlib and Seaborn.
What Are Empty Circles in Scatter Plots?
Empty circles in scatter plots represent points in a dataset without any fill color. They are often used to highlight the presence of data points without obscuring overlapping points, making it easier to visualize distributions and clusters. Empty circles can also be useful for distinguishing between different groups of data.
Before we start creating scatter plots, ensure we have the following libraries installed:
pip install matplotlib seaborn numpy pandas
Now we will discuss step-by-step implementation of How to Do a Scatter Plot with Empty Circles in Python.
Step 1: Import the Necessary Libraries
First, we need to import the necessary libraries:
import matplotlib.pyplot as plt
import numpy as np
Step 2: Prepare our Data
We can either use our dataset or create a sample dataset for demonstration. Here, we’ll generate some random data:
# Generate random data
# For reproducibility
np.random.seed(0)
# X-axis values
x = np.random.rand(50) * 10
# Y-axis values
y = np.random.rand(50) * 10
Step 3: Create the Scatter Plot
Now, we can create a scatter plot with empty circles using the scatter
function:
# Create a scatter plot with empty circles
plt.figure(figsize=(8, 6))
# s is the size of the circles
plt.scatter(x, y, facecolors='none', edgecolors='blue', s=100)
plt.title('Scatter Plot with Empty Circles')
plt.xlabel('X-axis Label')
plt.ylabel('Y-axis Label')
plt.grid(True)
plt.show()
Output:

facecolors='none'
: This parameter makes the circles empty (no fill color).edgecolors='blue'
: This parameter sets the color of the circle's edges to blue.s=100
: This parameter sets the size of the circles.
We should see a scatter plot where all points are represented by empty blue circles.
Creating a Scatter Plot with Seaborn
Seaborn, built on top of Matplotlib, provides a more aesthetically pleasing way to create visualizations with less code. To create a scatter plot with empty circles using Seaborn, follow these steps:
Step 1: Import Seaborn
Make sure to import Seaborn along with the other libraries:
import seaborn as sns
import pandas as pd
Step 2: Prepare our Data
We can create a DataFrame to hold our data:
# Create a DataFrame
data = pd.DataFrame({
'X': x,
'Y': y
})
Step 3: Create the Scatter Plot
Use Seaborn’s scatterplot
function to create the plot:
# Create a scatter plot with empty circles
plt.figure(figsize=(8, 6))
sns.scatterplot(data=data, x='X', y='Y', edgecolor='blue', facecolor='none', s=100)
plt.title('Scatter Plot with Empty Circles using Seaborn')
plt.xlabel('X-axis Label')
plt.ylabel('Y-axis Label')
plt.grid(True)
plt.show()
Output:

edgecolor='blue'
: This sets the color of the edges of the circles.facecolor='none'
: This makes the circles empty.s=100
: This sets the size of the circles.
We should see a scatter plot similar to the one created with Matplotlib, but with Seaborn's styling applied.
Conclusion
Creating scatter plots with empty circles in Python can enhance the clarity of our visualizations, especially when dealing with overlapping data points. Both Matplotlib and Seaborn provide easy methods to achieve this customization, allowing us to create visually appealing and informative plots.