Skip to content

00-Scatter-Plots

Updated
17 Sept 2026
1 min read
7 sections
Page 36 of 117
Python & Machine Learning

Scatter Plots

Scatter plots can show how different features are related to one another, the main theme between all relational plot types is they display how features are interconnected to each other. There are many different types of plots that can be used to show this, so let's explore the scatterplot() as well as general seaborn parameters applicable to other plot types.


Data

We'll use some generated data from: http://roycekimmons.com/tools/generated_data

python
df = pd.read_csv("dm_office_sales.csv")
python
df.head()
Out · table
division
level of education
training level
work experience
salary
36 more lines
sales
0
printers
some college
2
6
91684
372302
1
printers
associate's degree
2
10
119679
495660
2
peripherals
high school
0
9
82045
320453
3
office supplies
associate's degree
2
5
92949
377148
4
office supplies
high school
1
5
71280
312802
python
df.info()
Out · stdout
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 1000 entries, 0 to 999
Data columns (total 6 columns):
 #   Column              Non-Null Count  Dtype 
---  ------              --------------  ----- 
8 more lines
 0   division            1000 non-null   object
 1   level of education  1000 non-null   object
 2   training level      1000 non-null   int64 
 3   work experience     1000 non-null   int64 
 4   salary              1000 non-null   int64 
 5   sales               1000 non-null   int64 
dtypes: int64(4), object(2)
memory usage: 47.0+ KB

Scatterplot

python
sns.scatterplot(x='salary',y='sales',data=df)
Out · result
<matplotlib.axes._subplots.AxesSubplot at 0x2089e370088>
Out · plot
Output 1

Connecting to Figure in Matplotlib

Note how matplotlib is still connected to seaborn underneath (even without importing matplotlib.pyplot), since seaborn itself is directly making a Figure call with matplotlib. We can import matplotlib.pyplot and make calls to directly effect the seaborn figure.

python
plt.figure(figsize=(12,8))
sns.scatterplot(x='salary',y='sales',data=df)
Out · result
<matplotlib.axes._subplots.AxesSubplot at 0x2089fb16a08>
Out · plot
Output 2

Seaborn Parameters

The hue and palette parameters are commonly available around many plot calls in seaborn.

hue

Color points based off a categorical feature in the DataFrame

python
plt.figure(figsize=(12,8))
sns.scatterplot(x='salary',y='sales',data=df,hue='division')
Out · result
<matplotlib.axes._subplots.AxesSubplot at 0x2089fb0fe88>
Out · plot
Output 3
python
plt.figure(figsize=(12,8))
sns.scatterplot(x='salary',y='sales',data=df,hue='work experience')
Out · result
<matplotlib.axes._subplots.AxesSubplot at 0x2089fc3d848>
Out · plot
Output 4

Choosing a palette from Matplotlib's cmap: https://matplotlib.org/tutorials/colors/colormaps.html

python
plt.figure(figsize=(12,8))
sns.scatterplot(x='salary',y='sales',data=df,hue='work experience',palette='viridis')
Out · result
<matplotlib.axes._subplots.AxesSubplot at 0x2089fcbbdc8>
Out · plot
Output 5

Scatterplot Parameters

These parameters are more specific to the scatterplot() call

size

Allows you to size based on another column

python
plt.figure(figsize=(12,8))
sns.scatterplot(x='salary',y='sales',data=df,size='work experience')
Out · result
<matplotlib.axes._subplots.AxesSubplot at 0x2089fcb7188>
Out · plot
Output 6

*Use s= if you want to change the marker size to be some uniform integer value*

python
plt.figure(figsize=(12,8))
sns.scatterplot(x='salary',y='sales',data=df,s=200)
Out · result
<matplotlib.axes._subplots.AxesSubplot at 0x208a00c1708>
Out · plot
Output 7
python
plt.figure(figsize=(12,8))
sns.scatterplot(x='salary',y='sales',data=df,s=200,linewidth=0,alpha=0.2)
Out · result
<matplotlib.axes._subplots.AxesSubplot at 0x208a077b908>
Out · plot
Output 8

style

Automatically choose styles based on another categorical feature in the dataset. Optionally use the markers= parameter to pass a list of marker choices based off matplotlib, for example: ['*','+','o']

python
plt.figure(figsize=(12,8))
sns.scatterplot(x='salary',y='sales',data=df,style='level of education')
Out · result
<AxesSubplot:xlabel='salary', ylabel='sales'>
Out · plot
Output 9
python
plt.figure(figsize=(12,8))
# Sometimes its nice to do BOTH hue and style off the same column
sns.scatterplot(x='salary',y='sales',data=df,style='level of education',hue='level of education',s=100)
Out · result
<AxesSubplot:xlabel='salary', ylabel='sales'>
Out · plot
Output 10

Exporting a Seaborn Figure

python
plt.figure(figsize=(12,8))
sns.scatterplot(x='salary',y='sales',data=df,style='level of education',hue='level of education',s=100)

# Call savefig in the same cell
plt.savefig('example_scatter.jpg')
Out · plot
Output 11