How to Do a Scatter Plot with Empty Circles in Python
Last Updated :
27 Sep, 2024
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:
Python
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:
Python
# 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:
Python
# 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:
Create the Scatter Plotfacecolors='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:
Python
import seaborn as sns
import pandas as pd
Step 2: Prepare our Data
We can create a DataFrame to hold our data:
Python
# 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:
Python
# 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:
Scatter Plot with Empty Circles in Pythonedgecolor='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.
Similar Reads
How to Draw a Circle Using Matplotlib in Python? A Circle is a mathematical figure formed by joining all points lying on the same plane and are at equal distance from a given point. We can plot a circle in python using Matplotlib. There are multiple ways to plot a Circle in python using Matplotlib. Method 1: Using matplotlib.patches.Circle() func
3 min read
How to create a Scatter Plot with several colors in Matplotlib? Matplotlib is a plotting library for creating static, animated, and interactive visualizations in Python. Matplotlib can be used in Python scripts, the Python and IPython shell, web application servers, and various graphical user interface toolkits like Tkinter, awxPython, etc. In this article, we w
3 min read
What Is a Scatter Plot in Python? Scatter plots are a fundamental tool in data visualization, providing a visual representation of the relationship between two variables. In Python, scatter plots are commonly created using libraries such as Matplotlib and Seaborn. This article will delve into the concept of scatter plots, their appl
6 min read
How to Draw Shapes in Matplotlib with Python Matplotlib provides a collection of classes and functions that allow you to draw and manipulate various shapes on your plots. Whether you're adding annotations, creating diagrams, or visualizing data, understanding how to use these tools effectively will enhance your ability to create compelling vis
2 min read
How to make a basic Scatterplot using Python-Plotly? Plotly is a graphing library for making high quality interactive graphs and charts. It is an open source library used for data visualization . This library can be used with three programming languages namely Python, R and Javascript. Using Plotly is very easy and you can make any type of graph using
2 min read