Introduction and Overview

Welcome! Today, we'll explore scatter plots and their creation with Seaborn, a Python library built on Matplotlib. We will master the construction, customization, and interpretation of scatter plots. Let's get started!

Unveiling Scatter Plots

A scatter plot is a data visualization tool that represents two variables from a dataset as points on a Cartesian graph. Scatter plots are utilized in exploring correlations between variables.

Introduction to Seaborn

Meet Seaborn, a Python library designed to create beautiful statistical graphics. It facilitates quick and easy creation of colorful and informative visuals from complex datasets.

Introducing Dataset

We use the scatterplot() function to create a scatter plot in Seaborn. We provide it with our data and the names of the columns to search for x and y values. Let's illustrate this concept using a small dataset, which is created this way:

import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd

# Create a dataset
df = pd.DataFrame({
    "hours": [1, 8, 2, 6, 6, 4, 4, 9, 8, 10],
    "scores": [30, 70, 35, 90, 95, 70, 50, 100, 85, 97]
})

This dummy dataset maps the number of study hours for ten students to their respective test scores.

Building Scatter Plots with Seaborn

Now, let's plot this data using scatterplot().

# Create scatter plot
sns.scatterplot(x='hours', y='scores', data=df)
plt.show()

This scatter plot shows a clear positive correlation: as the number of study hours increases, the test scores also increase. Note that we use the plt.show function from matplotlib to show seaborn's plots.

Customizing Scatter Plots

Seaborn allows for extensive plot customization. Let's add a title and labels to our axes to make our plot more understandable.

# Customize scatter plot
sns.scatterplot(x='hours', y='scores', data=df)
plt.title('Study Hours vs. Test Scores')
plt.xlabel('Hours Studied')
plt.ylabel('Test Scores')
plt.show()

Now, complete with a title and labels, our plot is much more straightforward and informative.

Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal