ℹ️ Skipped - page is already crawled
| Filter | Status | Condition | Details |
|---|---|---|---|
| HTTP status | PASS | download_http_code = 200 | HTTP 200 |
| Age cutoff | PASS | download_stamp > now() - 6 MONTH | 0.3 months ago |
| History drop | PASS | isNull(history_drop_reason) | No drop reason |
| Spam/ban | PASS | fh_dont_index != 1 AND ml_spam_score = 0 | ml_spam_score=0 |
| Canonical | PASS | meta_canonical IS NULL OR = '' OR = src_unparsed | Not set |
| Property | Value |
|---|---|
| URL | https://python-graph-gallery.com/40-basic-scatterplot-seaborn/ |
| Last Crawled | 2026-04-07 09:32:03 (10 days ago) |
| First Indexed | 2017-10-05 18:00:06 (8 years ago) |
| HTTP Status Code | 200 |
| Meta Title | Basic Scatterplot with Seaborn |
| Meta Description | Plotting a basic scatterplot with seaborn. |
| Meta Canonical | null |
| Boilerpipe Text | Libraries
First, we need to load a few libraries:
seaborn
: for creating the scatterplot
matplotlib
: for displaying the plot
pandas
: for data manipulation
import
seaborn
as
sns
import
matplotlib
.
pyplot
as
plt
import
pandas
as
pd
Dataset
Since
scatter plot
are made for visualizing
relationships between two numerical variables
, we need a dataset that contains at least two numerical columns.
Here, we will use the
iris
dataset that we
load
directly from the gallery:
path
=
'https://raw.githubusercontent.com/holtzy/The-Python-Graph-Gallery/master/static/data/iris.csv'
df
=
pd
.
read_csv
(
path
)
df
.
head
(
)
sepal_length
sepal_width
petal_length
petal_width
species
0
5.1
3.5
1.4
0.2
setosa
1
4.9
3.0
1.4
0.2
setosa
2
4.7
3.2
1.3
0.2
setosa
3
4.6
3.1
1.5
0.2
setosa
4
5.0
3.6
1.4
0.2
setosa
Scatter plot
A
scatterplot
can be made using
scatterplot()
function of
seaborn
library. An example dataset from seaborn repository, iris dataset, is used in the example. The plot shows the relationship between sepal lenght and width of plants. In order to show the most basic utilization of this function, the following parameters should be provided:
x
: positions of points on the X axis
y
: positions of points on the Y axis
sns
.
scatterplot
(
x
=
df
[
"sepal_length"
]
,
y
=
df
[
"sepal_width"
]
)
plt
.
show
(
)
Alternatively: you can use the following syntax:
sns
.
scatterplot
(
data
=
df
,
x
=
"sepal_length"
,
y
=
"sepal_width"
)
plt
.
show
(
)
Customize the scatter plot
The
scatterplot()
function accepts the following arguments (
among others
):
color
: of the points
edgecolor
: edge colour of the points
alpha
: transparency of points (
between 0 and 1
)
s
: dot size
You can find all the available colors
here
.
sns
.
scatterplot
(
x
=
df
[
"sepal_length"
]
,
y
=
df
[
"sepal_width"
]
,
color
=
"red"
,
edgecolor
=
"darkred"
,
alpha
=
0.6
,
s
=
200
)
plt
.
show
(
) |
| Markdown | [← Graph Gallery](https://python-graph-gallery.com/)
[Chart types](https://python-graph-gallery.com/40-basic-scatterplot-seaborn/)
[Tools](https://python-graph-gallery.com/40-basic-scatterplot-seaborn/)
[All](https://python-graph-gallery.com/all-charts)[Best](https://python-graph-gallery.com/best-python-chart-examples)[Libs](https://python-graph-gallery.com/best-dataviz-packages)
[Related](https://python-graph-gallery.com/40-basic-scatterplot-seaborn/)
[Learn](https://www.matplotlib-journey.com/)
Subscribe
# Basic Scatterplot with Seaborn



***
A [scatterplot](https://www.data-to-viz.com/graph/scatter.html) is a type of chart that shows the relationship between two numerical variables. Each member of the dataset gets plotted as a point whose **x-y coordinates** relates to its values for the two variables.
This example shows how to create a scatterplot with [seaborn](https://python-graph-gallery.com/seaborn/) and how to add a **regression line**.
[Scatterplot section](https://python-graph-gallery.com/scatter-plot/)
[About this chart](https://www.data-to-viz.com/graph/scatter.html)
## Libraries
First, we need to load a few libraries:
- [seaborn](https://python-graph-gallery.com/seaborn/): for creating the scatterplot
- [matplotlib](https://python-graph-gallery.com/matplotlib/): for displaying the plot
- [pandas](https://python-graph-gallery.com/pandas/): for data manipulation
```
import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
```
## Dataset
Since [scatter plot](https://python-graph-gallery.com/scatter-plot/) are made for visualizing **relationships between two numerical variables**, we need a dataset that contains at least two numerical columns.
Here, we will use the `iris` dataset that we **load** directly from the gallery:
```
path = 'https://raw.githubusercontent.com/holtzy/The-Python-Graph-Gallery/master/static/data/iris.csv'
df = pd.read_csv(path)
df.head()
```
| | sepal\_length | sepal\_width | petal\_length | petal\_width | species |
|---|---|---|---|---|---|
| 0 | 5\.1 | 3\.5 | 1\.4 | 0\.2 | setosa |
| 1 | 4\.9 | 3\.0 | 1\.4 | 0\.2 | setosa |
| 2 | 4\.7 | 3\.2 | 1\.3 | 0\.2 | setosa |
| 3 | 4\.6 | 3\.1 | 1\.5 | 0\.2 | setosa |
| 4 | 5\.0 | 3\.6 | 1\.4 | 0\.2 | setosa |
## Scatter plot
A [scatterplot](https://python-graph-gallery.com/scatter-plot) can be made using `scatterplot()` function of [seaborn](https://python-graph-gallery.com/seaborn) library. An example dataset from seaborn repository, iris dataset, is used in the example. The plot shows the relationship between sepal lenght and width of plants. In order to show the most basic utilization of this function, the following parameters should be provided:
- `x` : positions of points on the X axis
- `y` : positions of points on the Y axis
```
sns.scatterplot(x=df["sepal_length"], y=df["sepal_width"])
plt.show()
```

*Alternatively: you can use the following syntax:*
```
sns.scatterplot(data=df, x="sepal_length", y="sepal_width")
plt.show()
```

## Customize the scatter plot
The `scatterplot()` function accepts the following arguments (**among others**):
- `color`: of the points
- `edgecolor` : edge colour of the points
- `alpha` : transparency of points (**between 0 and 1**)
- `s`: dot size
You can find all the available colors [here](https://python-graph-gallery.com/python-colors).
```
sns.scatterplot(
x=df["sepal_length"],
y=df["sepal_width"],
color="red",
edgecolor="darkred",
alpha=0.6,
s=200
)
plt.show()
```

## Going further
This post explains how to create a [scatterplot](http://python-graph-gallery.com/scatter-plot/) with [seaborn](http://python-graph-gallery.com/seaborn/).
You might be interested in more advanced examples on
- [how to visualize linear regression](https://python-graph-gallery.com/42-custom-linear-regression-fit-seaborn)
- [how to color points according to a third variable](https://python-graph-gallery.com/43-use-categorical-variable-to-color-scatterplot-seaborn).
- [discover more marker customization](https://python-graph-gallery.com/41-control-marker-features).
## Correlation
[  \+](https://python-graph-gallery.com/scatter-plot/)
Scatterplot
[  \+](https://python-graph-gallery.com/heatmap/)
Heatmap
[  \+](https://python-graph-gallery.com/correlogram/)
Correlogram
[  \+](https://python-graph-gallery.com/bubble-plot/)
Bubble
[  \+](https://python-graph-gallery.com/connected-scatter-plot/)
Connected Scatter
[  \+](https://python-graph-gallery.com/2d-density-plot/)
2D Density
## 🚨 Grab the Data To Viz poster\!
Do you know all the chart types? Do you know which one you should pick? I made a **decision tree** that answers those questions. You can download it for free\!

Copyright © the Python Graph Gallery 2024
[Privacy](https://python-graph-gallery.com/privacy/) \| [License](https://github.com/holtzy/The-Python-Graph-Gallery/blob/master/LICENSE) \| [About](https://python-graph-gallery.com/about/)
Libraries
Dataset
Scatter plot
Customize the scatter plot
Going further
Related charts
Edit this page |
| Readable Markdown | ## Libraries
First, we need to load a few libraries:
- [seaborn](https://python-graph-gallery.com/seaborn/): for creating the scatterplot
- [matplotlib](https://python-graph-gallery.com/matplotlib/): for displaying the plot
- [pandas](https://python-graph-gallery.com/pandas/): for data manipulation
```
import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
```
## Dataset
Since [scatter plot](https://python-graph-gallery.com/scatter-plot/) are made for visualizing **relationships between two numerical variables**, we need a dataset that contains at least two numerical columns.
Here, we will use the `iris` dataset that we **load** directly from the gallery:
```
path = 'https://raw.githubusercontent.com/holtzy/The-Python-Graph-Gallery/master/static/data/iris.csv'
df = pd.read_csv(path)
df.head()
```
| | sepal\_length | sepal\_width | petal\_length | petal\_width | species |
|---|---|---|---|---|---|
| 0 | 5\.1 | 3\.5 | 1\.4 | 0\.2 | setosa |
| 1 | 4\.9 | 3\.0 | 1\.4 | 0\.2 | setosa |
| 2 | 4\.7 | 3\.2 | 1\.3 | 0\.2 | setosa |
| 3 | 4\.6 | 3\.1 | 1\.5 | 0\.2 | setosa |
| 4 | 5\.0 | 3\.6 | 1\.4 | 0\.2 | setosa |
## Scatter plot
A [scatterplot](https://python-graph-gallery.com/scatter-plot) can be made using `scatterplot()` function of [seaborn](https://python-graph-gallery.com/seaborn) library. An example dataset from seaborn repository, iris dataset, is used in the example. The plot shows the relationship between sepal lenght and width of plants. In order to show the most basic utilization of this function, the following parameters should be provided:
- `x` : positions of points on the X axis
- `y` : positions of points on the Y axis
```
sns.scatterplot(x=df["sepal_length"], y=df["sepal_width"])
plt.show()
```

*Alternatively: you can use the following syntax:*
```
sns.scatterplot(data=df, x="sepal_length", y="sepal_width")
plt.show()
```

## Customize the scatter plot
The `scatterplot()` function accepts the following arguments (**among others**):
- `color`: of the points
- `edgecolor` : edge colour of the points
- `alpha` : transparency of points (**between 0 and 1**)
- `s`: dot size
You can find all the available colors [here](https://python-graph-gallery.com/python-colors).
```
sns.scatterplot(
x=df["sepal_length"],
y=df["sepal_width"],
color="red",
edgecolor="darkred",
alpha=0.6,
s=200
)
plt.show()
```
 |
| Shard | 35 (laksa) |
| Root Hash | 7877591490014409035 |
| Unparsed URL | com,python-graph-gallery!/40-basic-scatterplot-seaborn/ s443 |