Open In App

Scatterplot using Seaborn in Python

Last Updated : 27 May, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Seaborn is an amazing visualization library for statistical graphics plotting in Python. It provides beautiful default styles and color palettes to make statistical plots more attractive. It is built on the top of matplotlib library and also closely integrated into the data structures from pandas.

What is a scatterplot?

A scatter plot displays points on a two-dimensional axis to show the relationship between two variables. Each dot represents an observation from your dataset. With Seaborn’s scatterplot() function, you can easily:

  • Show relationships
  • Differentiate groups using hue (color), style (marker) and size (point radius)
  • Improve accessibility and clarity with semantic mapping

Syntax

seaborn.scatterplot(
x=None, y=None,
hue=None, style=None, size=None,
data=None, palette=None,
legend='brief', alpha='auto',
**kwargs
)

Parameters:

Parameter

Description

x, y

Numeric variables for the X and Y axes

data

Pandas DataFrame

hue

Variable that maps to different colors

style

Variable that maps to different marker shapes

size

Variable that maps to different marker sizes

palette

Defines the color palette

alpha

Transparency of points

legend

Controls legend visibility and behavior

Returns: This method returns the Axes object with the plot drawn onto it.

Examples

Example 1: In this example, we are creating a basic scatter plot with the FMRI dataset. We plot the timepoint on the x-axis and the signal on the y-axis to observe how the signal changes over time.

Python
import seaborn as sns
import matplotlib.pyplot as plt

sns.set(style='whitegrid')
fmri = sns.load_dataset("fmri")

sns.scatterplot(x="timepoint", y="signal", data=fmri)
plt.title("FMRI Signal Over Time")
plt.show()

Output

Output
Using seaborn.sactterplot()

Explanation: sns.set(style='whitegrid') sets a clean plot style with gridlines. sns.load_dataset("fmri") loads brain signal data over time. sns.scatterplot(x="timepoint", y="signal", data=fmri) creates a scatter plot showing how FMRI signals vary with time.

Example 2: In this example, we extend the basic FMRI scatter plot by adding color (hue) based on the region and different markers (style) based on the event.

Python
sns.scatterplot(
    x="timepoint", y="signal", 
    hue="region", style="event", 
    data=fmri
)
plt.title("FMRI Signal by Region and Event")
plt.show()

Output

Output
Using seaborn.sactterplot()

Explanation: sns.scatterplot(x="timepoint", y="signal", hue="region", style="event", data=fmri) creates a scatter plot of FMRI signals over time, using different colors for regions and marker styles for events.

Example 3: In this example, we use the Tips dataset to create a scatter plot showing how tips vary across different days of the week. The day is plotted on the x-axis and the tip amount on the y-axis.

Python
tips = sns.load_dataset("tips")
sns.scatterplot(x="day", y="tip", data=tips)
plt.title("Tips by Day")
plt.show()

Output

Output
Using seaborn.sactterplot()

Explanation: sns.load_dataset("tips") loads a dataset containing restaurant tipping data. sns.scatterplot(x="day", y="tip", data=tips) creates a scatter plot showing tip amounts given on different days.

Grouping variables in Seaborn Scatter Plot with different attributes

1. Adding the marker attributes: The circle is used to represent the data point and the default marker here is a blue circle. In the above output, we are seeing the default output for the marker, but we can customize this blue circle with marker attributes.

Python
seaborn.scatterplot(x='day', y='tip', data= tip, marker = '+')

Output

2. Adding the hue attributes: It will produce data points with different colors. Hue can be used to group to multiple data variable and show the dependency of the passed data values are to be plotted.

Syntax: seaborn.scatterplot( x, y, data, hue)

Python
seaborn.scatterplot(x='day', y='tip', data=tip, hue='time')

Output

In the above example, we can see how the tip and day bill is related to whether it was lunchtime or dinner time. The blue color has represented the Dinner and the orange color represents the Lunch.

Let's check for a hue = " day "

Python
seaborn.scatterplot(x='day', y='tip', data=tip, hue='day')

3. Adding the style attributes: Grouping variable that will produce points with different markers. Using style we can generate the scatter grouping variable that will produce points with different markers.

Syntax: seaborn.scatterplot( x, y, data, style)

Python
seaborn.scatterplot(x='day', y='tip', data=tip, hue="time", style="time")

Output

4. Adding the palette attributes: Using the palette we can generate the point with different colors. In this below example we can see the palette can be responsible for a generate the scatter plot with different colormap values.

Syntax: seaborn.scatterplot( x, y, data, palette="color_name")

Python
seaborn.scatterplot(x='day', y='tip', data=tip, hue='time', palette='pastel')

Output

5. Adding size attributes: Using size we can generate the point and we can produce points with different sizes.

Syntax: seaborn.scatterplot( x, y, data, size)

Python
seaborn.scatterplot(x='day', y='tip', data=tip ,hue='size', size = "size")

Output

6. Adding legend attributes: We can control the legend display using the legend parameter: legend='full' shows all groups, legend='brief' shows a sample for numeric variables, and legend=False hides the legend completely.

Syntax: seaborn.scatterplot( x, y, data, legend=''brief)

Python
seaborn.scatterplot(x='day', y='tip', data=tip, hue='day',
                    sizes=(30, 200), legend='brief')

Output

7. Adding alpha attributes: Using alpha we can control proportional opacity of the points. We can decrease and increase the opacity.

Syntax: seaborn.scatterplot( x, y, data, alpha="0.2")

Python
seaborn.scatterplot(x='day', y='tip', data=tip, alpha = 0.1)

Output


Next Article
Article Tags :
Practice Tags :

Similar Reads