ℹ️ 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.4 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/508-connected-scatter-plot-seaborn/ |
| Last Crawled | 2026-03-30 12:59:16 (13 days ago) |
| First Indexed | 2023-11-02 17:49:11 (2 years ago) |
| HTTP Status Code | 200 |
| Meta Title | Connected scatter plot with Seaborn |
| Meta Description | Plotting basic connected scatter plots using Seaborn and Matplotlib, with customisation features. |
| Meta Canonical | null |
| Boilerpipe Text | About scatter plots
Simple scatter plot
A
simple scatter plot
is a graphical representation that displays
individual data points as dots on a two-dimensional plane
. Each dot represents a single observation or data point, and its position on the plot corresponds to the values of two variables.
Connected scatter plot
A
connected scatter plot
, also known as a line plot with markers, is similar to a simple scatter plot but with the addition of
lines connecting the data points in the order they appear
. This type of plot is often used to visualize the temporal or sequential relationships between two variables.
Libraries
First, you need to install the following librairies:
seaborn
is used for creating the chart witht the
lineplot()
function
matplotlib
is used for plot customization purposes
numpy
is used to generate some data
pandas
is used to store the data generated with numpy
Don't forget to install seaborn if you haven't already done so with the
pip install seaborn
command.
# Use the darkgrid theme for seaborn
import
seaborn
as
sns
sns
.
set_theme
(
style
=
"darkgrid"
)
import
matplotlib
.
pyplot
as
plt
import
numpy
as
np
import
pandas
as
pd
Dataset
For scatter plot, we need
2 numeric variables
. We randomly generate these variables thanks to numpy's
random.uniform()
and
random.normal()
function that, respectively, generate uniformly and normally distributed data.
# Generate random numeric values, where y is a function of x
x
=
np
.
random
.
uniform
(
3
,
1
,
100
)
y
=
x
*
10
+
np
.
random
.
normal
(
3
,
2
,
100
)
data
=
{
'x'
:
x
,
'y'
:
y
,
}
df
=
pd
.
DataFrame
(
data
)
Basic connected scatter plot
The following code displays a
simple connected scatter plot
, with a title and an axis name, thanks to the
lineplot()
function from
Seaborn
.
plt
.
figure
(
figsize
=
(
8
,
6
)
)
# Width and Height of the chart
sns
.
lineplot
(
x
=
'x'
,
y
=
'y'
,
data
=
df
,
marker
=
'o'
,
# Style used to mark the join between 2 points
)
plt
.
xlabel
(
'X-axis'
)
# x-axis name
plt
.
ylabel
(
'Y-axis'
)
# y-axis name
plt
.
title
(
'Simple Connected Scatter Plot'
)
# Add a title
plt
.
show
(
)
# Display the graph
Customization features
Display multiple lines on the same graph
To our previous dataset, we add a
3rd variable
which will be categorical, named
z
. It will be used to separate our observations according to their label in this variable. In practice, just add
hue='z'
(or the
name of the variable
you want to use to divide the rows) when using the
lineplot
function.
Specify your own colors
You can use the
palette
parameter to specify
your own colors
for lines. If you want a specific color for each group, I recommend
using a dictionary
with
label as key
and
color as value
(which is what we do in the following example). But it's also possible to
make a list of colors
(however, it must be the same length as the number of distinct labels in 'z').
# Generate random numeric values, where y is a function of x
x
=
np
.
random
.
uniform
(
3
,
0.1
,
30
)
y
=
x
*
10
+
np
.
random
.
normal
(
3
,
10
,
30
)
z
=
[
'Group1'
if
i
<
25
else
'Group2'
for
i
in
y
]
# Categorical variable
data
=
{
'x'
:
x
,
'y'
:
y
,
'z'
:
z
,
}
df
=
pd
.
DataFrame
(
data
)
plt
.
figure
(
figsize
=
(
8
,
6
)
)
# Width and Height of the chart
sns
.
lineplot
(
x
=
'x'
,
y
=
'y'
,
hue
=
'z'
,
# Create 2 line plots according to labels in 'z'
data
=
df
,
marker
=
'o'
,
# Style used to mark the join between 2 points
palette
=
{
'Group1'
:
'red'
,
'Group2'
:
'purple'
}
,
# Colors of the lines
)
plt
.
xlabel
(
'X-axis'
)
# x-axis name
plt
.
ylabel
(
'Y-axis'
)
# y-axis name
plt
.
title
(
'Customized Connected Scatter Plot'
)
# Add a title
plt
.
show
(
)
# Display the graph
Customize lines and markers
You can also customize markers and lines, thanks to several arguments.
marker
: the style of the marker (
must be
in the following list:
o
,
s
,
d
,
^
,
v
,
<
,
>
,
p
,
*
,
+
,
x
,
h
)
markersize
: marker size
linestyle
: the style of the line (
must be
in the following list:
-
,
--
,
-.
,
:
,
None
)
plt
.
figure
(
figsize
=
(
8
,
6
)
)
# Width and Height of the chart
sns
.
lineplot
(
x
=
'x'
,
y
=
'y'
,
hue
=
'z'
,
# Create 2 line plots according to labels in 'z'
data
=
df
,
marker
=
'*'
,
# Style used to mark the join between 2 points
markersize
=
20
,
# Size of the marker
palette
=
{
'Group1'
:
'red'
,
'Group2'
:
'purple'
}
,
# Colors of the lines,
linestyle
=
'-.'
,
# Style used for the lines
)
plt
.
xlabel
(
'X-axis'
)
# x-axis name
plt
.
ylabel
(
'Y-axis'
)
# y-axis name
plt
.
title
(
'Customized Connected Scatter Plot'
)
# Add a title
plt
.
show
(
)
# Display the graph
A complete example that covers all the previous concepts
To give you some ideas for customization, here's a
complete example of a connected scatter plot
using the same concepts as above.
# Sample data
x
=
[
1
,
2
,
3
,
4
,
5
]
y
=
[
5
,
3
,
7
,
4
,
8
]
# Set Seaborn style
plt
.
figure
(
figsize
=
(
8
,
6
)
)
# Solid line with circle markers
sns
.
lineplot
(
x
=
x
,
y
=
y
,
linestyle
=
'-'
,
marker
=
'o'
,
markersize
=
8
,
label
=
'Solid Line'
,
color
=
'blue'
)
# Dashed line with square markers
sns
.
lineplot
(
x
=
x
,
y
=
[
i
+
1
for
i
in
y
]
,
linestyle
=
'--'
,
marker
=
's'
,
markersize
=
8
,
label
=
'Dashed Line'
,
color
=
'green'
)
# Dash-dot line with triangle up markers
sns
.
lineplot
(
x
=
x
,
y
=
[
i
+
2
for
i
in
y
]
,
linestyle
=
'-.'
,
marker
=
'^'
,
markersize
=
20
,
label
=
'Dash-dot Line'
,
color
=
'purple'
)
# Dotted line with asterisk markers
sns
.
lineplot
(
x
=
x
,
y
=
[
i
+
3
for
i
in
y
]
,
linestyle
=
':'
,
marker
=
'*'
,
markersize
=
15
,
label
=
'Dotted Line'
,
color
=
'orange'
)
plt
.
title
(
'Customized Line and Scatter Plot with Seaborn'
)
# Add a title
plt
.
xlabel
(
'X-axis'
)
# x-axis name
plt
.
ylabel
(
'Y-axis'
)
# x-axis name
plt
.
legend
(
loc
=
'upper left'
)
# Add a legend
plt
.
show
(
)
# Display the graph |
| Markdown | [← Graph Gallery](https://python-graph-gallery.com/)
[Chart types](https://python-graph-gallery.com/508-connected-scatter-plot-seaborn/)
[Tools](https://python-graph-gallery.com/508-connected-scatter-plot-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/508-connected-scatter-plot-seaborn/)
[Learn](https://www.matplotlib-journey.com/)
Subscribe
# Connected scatter plot with Seaborn



***
This post describes how to create **basic connected scatter plots** using [seaborn](https://python-graph-gallery.com/seaborn/) and [matplotlib](https://python-graph-gallery.com/matplotlib/). If you want to know more about scatter plot, check out [the scatter plot section](https://python-graph-gallery.com/scatter-plot/).
[Connected Scatter section](https://python-graph-gallery.com/connected-scatter-plot/)
[About this chart](https://www.data-to-viz.com/graph/connectedscatter.html)
## About scatter plots
### Simple scatter plot
A `simple scatter plot` is a graphical representation that displays **individual data points as dots on a two-dimensional plane**. Each dot represents a single observation or data point, and its position on the plot corresponds to the values of two variables.
### Connected scatter plot
A `connected scatter plot`, also known as a line plot with markers, is similar to a simple scatter plot but with the addition of **lines connecting the data points in the order they appear**. This type of plot is often used to visualize the temporal or sequential relationships between two variables.
## Libraries
First, you need to install the following librairies:
- [seaborn](https://python-graph-gallery.com/seaborn/) is used for creating the chart witht the `lineplot()` function
- [matplotlib](https://python-graph-gallery.com/matplotlib/) is used for plot customization purposes
- `numpy` is used to generate some data
- `pandas` is used to store the data generated with numpy
Don't forget to install seaborn if you haven't already done so with the `pip install seaborn` command.
```
# Use the darkgrid theme for seaborn
import seaborn as sns
sns.set_theme(style="darkgrid")
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
```
## Dataset
For scatter plot, we need **2 numeric variables**. We randomly generate these variables thanks to numpy's `random.uniform()` and `random.normal()` function that, respectively, generate uniformly and normally distributed data.
```
# Generate random numeric values, where y is a function of x
x = np.random.uniform(3,1,100)
y = x * 10 + np.random.normal(3,2,100)
data = {'x': x,
'y': y,
}
df = pd.DataFrame(data)
```
## Basic connected scatter plot
The following code displays a **simple connected scatter plot**, with a title and an axis name, thanks to the `lineplot()` function from [Seaborn](https://python-graph-gallery.com/seaborn/).
```
plt.figure(figsize=(8, 6)) # Width and Height of the chart
sns.lineplot(x='x',
y='y',
data=df,
marker='o', # Style used to mark the join between 2 points
)
plt.xlabel('X-axis') # x-axis name
plt.ylabel('Y-axis') # y-axis name
plt.title('Simple Connected Scatter Plot') # Add a title
plt.show() # Display the graph
```

## Customization features
### Display multiple lines on the same graph
To our previous dataset, we add a **3rd variable** which will be categorical, named `z`. It will be used to separate our observations according to their label in this variable. In practice, just add `hue='z'` (or the **name of the variable** you want to use to divide the rows) when using the `lineplot` function.
### Specify your own colors
You can use the `palette` parameter to specify **your own colors** for lines. If you want a specific color for each group, I recommend **using a dictionary** with *label as key* and *color as value* (which is what we do in the following example). But it's also possible to **make a list of colors** (however, it must be the same length as the number of distinct labels in 'z').
```
# Generate random numeric values, where y is a function of x
x = np.random.uniform(3,0.1,30)
y = x * 10 + np.random.normal(3,10,30)
z = ['Group1' if i < 25 else 'Group2' for i in y] # Categorical variable
data = {'x': x,
'y': y,
'z': z,
}
df = pd.DataFrame(data)
```
```
plt.figure(figsize=(8, 6)) # Width and Height of the chart
sns.lineplot(x='x',
y='y',
hue='z', # Create 2 line plots according to labels in 'z'
data=df,
marker='o', # Style used to mark the join between 2 points
palette={'Group1':'red',
'Group2':'purple'}, # Colors of the lines
)
plt.xlabel('X-axis') # x-axis name
plt.ylabel('Y-axis') # y-axis name
plt.title('Customized Connected Scatter Plot') # Add a title
plt.show() # Display the graph
```

## Customize lines and markers
You can also customize markers and lines, thanks to several arguments.
- `marker`: the style of the marker (**must be** in the following list: `o`, `s`, `d`, `^`, `v`, `<`, `>`, `p`, `*`, `+`, `x`, `h`)
- `markersize`: marker size
- `linestyle`: the style of the line (**must be** in the following list: `-`, `--`, `-.`, `:`, `None`)
```
plt.figure(figsize=(8, 6)) # Width and Height of the chart
sns.lineplot(x='x',
y='y',
hue='z', # Create 2 line plots according to labels in 'z'
data=df,
marker='*', # Style used to mark the join between 2 points
markersize=20, # Size of the marker
palette={'Group1':'red',
'Group2':'purple'}, # Colors of the lines,
linestyle='-.', # Style used for the lines
)
plt.xlabel('X-axis') # x-axis name
plt.ylabel('Y-axis') # y-axis name
plt.title('Customized Connected Scatter Plot') # Add a title
plt.show() # Display the graph
```

## A complete example that covers all the previous concepts
To give you some ideas for customization, here's a **complete example of a connected scatter plot** using the same concepts as above.
```
# Sample data
x = [1, 2, 3, 4, 5]
y = [5, 3, 7, 4, 8]
# Set Seaborn style
plt.figure(figsize=(8, 6))
# Solid line with circle markers
sns.lineplot(x=x, y=y, linestyle='-', marker='o', markersize=8, label='Solid Line', color='blue')
# Dashed line with square markers
sns.lineplot(x=x, y=[i + 1 for i in y], linestyle='--', marker='s', markersize=8, label='Dashed Line', color='green')
# Dash-dot line with triangle up markers
sns.lineplot(x=x, y=[i + 2 for i in y], linestyle='-.', marker='^', markersize=20, label='Dash-dot Line', color='purple')
# Dotted line with asterisk markers
sns.lineplot(x=x, y=[i + 3 for i in y], linestyle=':', marker='*', markersize=15, label='Dotted Line', color='orange')
plt.title('Customized Line and Scatter Plot with Seaborn') # Add a title
plt.xlabel('X-axis') # x-axis name
plt.ylabel('Y-axis') # x-axis name
plt.legend(loc='upper left') # Add a legend
plt.show() # Display the graph
```

## Going further
This post explained how to create a [connected scatter plot](https://python-graph-gallery.com/connected-scatter-plot/) with different customization features using Python and its [Seaborn](https://python-graph-gallery.com/seaborn/) library.
For more examples of **how to create or customize** your scatter plots with Python, check the [scatter plot section](https://python-graph-gallery.com/scatter-plot/). You might be interested in how to make a [scatter plot with a linear regression](https://python-graph-gallery.com/scatterplot-with-regression-fit-in-matplotlib/) on it.
## 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/)
About scatter plots
Libraries
Dataset
Basic connected scatter plot
Customization features
Customize lines and markers
A complete example that covers all the previous concepts
Going further
Related charts
Edit this page |
| Readable Markdown | ## About scatter plots
### Simple scatter plot
A `simple scatter plot` is a graphical representation that displays **individual data points as dots on a two-dimensional plane**. Each dot represents a single observation or data point, and its position on the plot corresponds to the values of two variables.
### Connected scatter plot
A `connected scatter plot`, also known as a line plot with markers, is similar to a simple scatter plot but with the addition of **lines connecting the data points in the order they appear**. This type of plot is often used to visualize the temporal or sequential relationships between two variables.
## Libraries
First, you need to install the following librairies:
- [seaborn](https://python-graph-gallery.com/seaborn/) is used for creating the chart witht the `lineplot()` function
- [matplotlib](https://python-graph-gallery.com/matplotlib/) is used for plot customization purposes
- `numpy` is used to generate some data
- `pandas` is used to store the data generated with numpy
Don't forget to install seaborn if you haven't already done so with the `pip install seaborn` command.
```
# Use the darkgrid theme for seaborn
import seaborn as sns
sns.set_theme(style="darkgrid")
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
```
## Dataset
For scatter plot, we need **2 numeric variables**. We randomly generate these variables thanks to numpy's `random.uniform()` and `random.normal()` function that, respectively, generate uniformly and normally distributed data.
```
# Generate random numeric values, where y is a function of x
x = np.random.uniform(3,1,100)
y = x * 10 + np.random.normal(3,2,100)
data = {'x': x,
'y': y,
}
df = pd.DataFrame(data)
```
## Basic connected scatter plot
The following code displays a **simple connected scatter plot**, with a title and an axis name, thanks to the `lineplot()` function from [Seaborn](https://python-graph-gallery.com/seaborn/).
```
plt.figure(figsize=(8, 6)) # Width and Height of the chart
sns.lineplot(x='x',
y='y',
data=df,
marker='o', # Style used to mark the join between 2 points
)
plt.xlabel('X-axis') # x-axis name
plt.ylabel('Y-axis') # y-axis name
plt.title('Simple Connected Scatter Plot') # Add a title
plt.show() # Display the graph
```

## Customization features
### Display multiple lines on the same graph
To our previous dataset, we add a **3rd variable** which will be categorical, named `z`. It will be used to separate our observations according to their label in this variable. In practice, just add `hue='z'` (or the **name of the variable** you want to use to divide the rows) when using the `lineplot` function.
### Specify your own colors
You can use the `palette` parameter to specify **your own colors** for lines. If you want a specific color for each group, I recommend **using a dictionary** with *label as key* and *color as value* (which is what we do in the following example). But it's also possible to **make a list of colors** (however, it must be the same length as the number of distinct labels in 'z').
```
# Generate random numeric values, where y is a function of x
x = np.random.uniform(3,0.1,30)
y = x * 10 + np.random.normal(3,10,30)
z = ['Group1' if i < 25 else 'Group2' for i in y] # Categorical variable
data = {'x': x,
'y': y,
'z': z,
}
df = pd.DataFrame(data)
```
```
plt.figure(figsize=(8, 6)) # Width and Height of the chart
sns.lineplot(x='x',
y='y',
hue='z', # Create 2 line plots according to labels in 'z'
data=df,
marker='o', # Style used to mark the join between 2 points
palette={'Group1':'red',
'Group2':'purple'}, # Colors of the lines
)
plt.xlabel('X-axis') # x-axis name
plt.ylabel('Y-axis') # y-axis name
plt.title('Customized Connected Scatter Plot') # Add a title
plt.show() # Display the graph
```

## Customize lines and markers
You can also customize markers and lines, thanks to several arguments.
- `marker`: the style of the marker (**must be** in the following list: `o`, `s`, `d`, `^`, `v`, `<`, `>`, `p`, `*`, `+`, `x`, `h`)
- `markersize`: marker size
- `linestyle`: the style of the line (**must be** in the following list: `-`, `--`, `-.`, `:`, `None`)
```
plt.figure(figsize=(8, 6)) # Width and Height of the chart
sns.lineplot(x='x',
y='y',
hue='z', # Create 2 line plots according to labels in 'z'
data=df,
marker='*', # Style used to mark the join between 2 points
markersize=20, # Size of the marker
palette={'Group1':'red',
'Group2':'purple'}, # Colors of the lines,
linestyle='-.', # Style used for the lines
)
plt.xlabel('X-axis') # x-axis name
plt.ylabel('Y-axis') # y-axis name
plt.title('Customized Connected Scatter Plot') # Add a title
plt.show() # Display the graph
```

## A complete example that covers all the previous concepts
To give you some ideas for customization, here's a **complete example of a connected scatter plot** using the same concepts as above.
```
# Sample data
x = [1, 2, 3, 4, 5]
y = [5, 3, 7, 4, 8]
# Set Seaborn style
plt.figure(figsize=(8, 6))
# Solid line with circle markers
sns.lineplot(x=x, y=y, linestyle='-', marker='o', markersize=8, label='Solid Line', color='blue')
# Dashed line with square markers
sns.lineplot(x=x, y=[i + 1 for i in y], linestyle='--', marker='s', markersize=8, label='Dashed Line', color='green')
# Dash-dot line with triangle up markers
sns.lineplot(x=x, y=[i + 2 for i in y], linestyle='-.', marker='^', markersize=20, label='Dash-dot Line', color='purple')
# Dotted line with asterisk markers
sns.lineplot(x=x, y=[i + 3 for i in y], linestyle=':', marker='*', markersize=15, label='Dotted Line', color='orange')
plt.title('Customized Line and Scatter Plot with Seaborn') # Add a title
plt.xlabel('X-axis') # x-axis name
plt.ylabel('Y-axis') # x-axis name
plt.legend(loc='upper left') # Add a legend
plt.show() # Display the graph
```
 |
| Shard | 35 (laksa) |
| Root Hash | 7877591490014409035 |
| Unparsed URL | com,python-graph-gallery!/508-connected-scatter-plot-seaborn/ s443 |