ℹ️ 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 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://www.datacamp.com/tutorial/python-seaborn-line-plot-tutorial |
| Last Crawled | 2026-04-07 04:31:52 (6 hours ago) |
| First Indexed | 2023-03-16 13:17:40 (3 years ago) |
| HTTP Status Code | 200 |
| Meta Title | Python Seaborn Line Plot Tutorial: Create Data Visualizations | DataCamp |
| Meta Description | Discover how to use Seaborn, a popular Python data visualization library, to create and customize line plots in Python. |
| Meta Canonical | null |
| Boilerpipe Text | A line plot is a relational data visualization showing how one continuous variable changes when another does. It's one of the most common graphs widely used in finance, sales, marketing, healthcare, natural sciences, and more.
In this tutorial, we'll discuss how to use Seaborn, a popular Python data visualization library, to create and customize line plots in Python.
Introducing the Dataset
To have something to practice seaborn line plots on, we'll first download a Kaggle dataset called
Daily Exchange Rates per Euro 1999-2024
. Then, we'll import all the necessary packages and read in and clean the dataframe. Without getting into details of the cleaning process, the code below demonstrates the steps to perform:
import
seaborn
as
sns
import
matplotlib
.
pyplot
as
plt
import
pandas
as
pd
daily_exchange_rate_df
=
pd
.
read_csv
(
'euro-daily-hist_1999_2022.csv'
)
daily_exchange_rate_df
=
daily_exchange_rate_df
.
iloc
[
:
,
[
0
,
1
,
4
,
-
2
]
]
daily_exchange_rate_df
.
columns
=
[
'Date'
,
'Australian dollar'
,
'Canadian dollar'
,
'US dollar'
]
daily_exchange_rate_df
=
pd
.
melt
(
daily_exchange_rate_df
,
id_vars
=
'Date'
,
value_vars
=
[
'Australian dollar'
,
'Canadian dollar'
,
'US dollar'
]
,
value_name
=
'Euro rate'
,
var_name
=
'Currency'
)
daily_exchange_rate_df
[
'Date'
]
=
pd
.
to_datetime
(
daily_exchange_rate_df
[
'Date'
]
)
daily_exchange_rate_df
=
daily_exchange_rate_df
[
daily_exchange_rate_df
[
'Date'
]
>=
'2022-12-01'
]
.
reset_index
(
drop
=
True
)
daily_exchange_rate_df
[
'Euro rate'
]
=
pd
.
to_numeric
(
daily_exchange_rate_df
[
'Euro rate'
]
)
print
(
f'Currencies:
{
daily_exchange_rate_df
.
Currency
.
unique
(
)
}
\n'
)
print
(
df
.
head
(
)
)
print
(
f'\n
{
daily_exchange_rate_df
.
Date
.
dt
.
date
.
min
(
)
}
/
{
daily_exchange_rate_df
.
Date
.
dt
.
date
.
max
(
)
}
'
)
Output
:
Currencies
:
[
'Australian dollar'
'Canadian dollar'
'US dollar'
]
Date Currency Euro rate
0
2023
-
01
-
27
Australian dollar
1.5289
1
2023
-
01
-
26
Australian dollar
1.5308
2
2023
-
01
-
25
Australian dollar
1.5360
3
2023
-
01
-
24
Australian dollar
1.5470
4
2023
-
01
-
23
Australian dollar
1.5529
2022
-
12
-
01
/
2023
-
01
-
27
Was this AI assistant helpful?
The resulting dataframe contains daily (business days) Euro rates for Australian, Canadian, and US dollars for the period from
01.12.2022
until
27.01.2023
inclusive.
Now, we're ready to dive into creating and customizing Python seaborn line plots.
Seaborn Line Plot Basics
To create a line plot in Seaborn, we can use one of the two functions:
lineplot()
or
relplot()
. Overall, they have a lot of functionality in common, together with identical parameter names. The main difference is that
relplot()
allows us to create line plots with multiple lines on different facets. Instead,
lineplot()
allows working with confidence intervals and data aggregation.
In this tutorial, we'll mostly use the
lineplot()
function.
The course
Introduction to Data Visualization with Seaborn
will help you learn and practice the main functions and methods of the seaborn library. You can also check out our
Seaborn tutorial for beginners
to get more familiar with the popular Python library.
Creating a single seaborn line plot
We can create a line plot showing the relationships between two continuous variables as follows:
usd
=
daily_exchange_rate_df
[
daily_exchange_rate_df
[
'Currency'
]
==
'US dollar'
]
.
reset_index
(
drop
=
True
)
sns
.
lineplot
(
x
=
'Date'
,
y
=
'Euro rate'
,
data
=
usd
)
Output
:
The above graph shows the EUR-USD rate dynamics. We defined the variables to plot on the
x
and
y
axes (the
x
and
y
parameters) and the dataframe (data) to take these variables from.
For comparison, to create the same plot using
relplot()
, we would write the following:
sns
.
relplot
(
x
=
'Date'
,
y
=
'Euro rate'
,
data
=
usd
,
kind
=
'line'
)
Was this AI assistant helpful?
Output
:
In this case, we passed in one more argument specific to the
relplot()
function:
kind='line'
. By default, this function creates a scatter plot.
Customizing a single seaborn line plot
We can customize the above chart in many ways to make it more readable and informative. For example, we can adjust the figure size, add title and axis labels, adjust the font size, customize the line, add and customize markers, etc. Let's see how to implement these improvements in seaborn.
Adjusting the figure size
Since Seaborn is built on top of matplotlib, we can use
matplotlib.pyplot
to adjust the figure size:
fig
=
plt
.
subplots
(
figsize
=
(
20
,
5
)
)
sns
.
lineplot
(
x
=
'Date'
,
y
=
'Euro rate'
,
data
=
usd
)
Was this AI assistant helpful?
Output
:
Instead, with relplot(), we can use the height and aspect (the width-to-height ratio) parameters for the same purpose:
sns
.
relplot
(
x
=
'Date'
,
y
=
'Euro rate'
,
data
=
usd
,
kind
=
'line'
,
height
=
6
,
aspect
=
4
)
Was this AI assistant helpful?
Output
:
Adding a title and axis labels
To add a graph title and axis labels, we can use the
set()
function on the seaborn line plot object passing in the title,
xlabel
, and
ylabel
arguments:
fig
=
plt
.
subplots
(
figsize
=
(
20
,
5
)
)
sns
.
lineplot
(
x
=
'Date'
,
y
=
'Euro rate'
,
data
=
usd
)
.
set
(
title
=
'Euro-USD rate'
,
xlabel
=
'Date'
,
ylabel
=
'Rate'
)
Was this AI assistant helpful?
Output
:
Adjusting the font size
A convenient way to adjust the font size is to use the
set_theme()
function and experiment with different values of the
font_scale
parameter:
fig
=
plt
.
subplots
(
figsize
=
(
20
,
5
)
)
sns
.
lineplot
(
x
=
'Date'
,
y
=
'Euro rate'
,
data
=
usd
)
.
set
(
title
=
'Euro-USD rate'
,
xlabel
=
'Date'
,
ylabel
=
'Rate'
)
sns
.
set_theme
(
style
=
'white'
,
font_scale
=
3
)
Was this AI assistant helpful?
Output
:
Note that we also added
style='white'
to avoid overriding the initial style.
Changing the line color, style, and size
To customize the plot line, we can pass in some optional parameters in common with
matplotlib.pyplot.plot
, such as
color
,
linestyle
, or
linewidth
:
fig
=
plt
.
subplots
(
figsize
=
(
20
,
5
)
)
sns
.
lineplot
(
x
=
'Date'
,
y
=
'Euro rate'
,
data
=
usd
,
linestyle
=
'dotted'
,
color
=
'magenta'
,
linewidth
=
5
)
.
set
(
title
=
'Euro-USD rate'
,
xlabel
=
'Date'
,
ylabel
=
'Rate'
)
sns
.
set_theme
(
style
=
'white'
,
font_scale
=
3
)
Was this AI assistant helpful?
Output
:
Adding markers and customizing their color, style, and size
It's possible to add markers on the line and customize their appearance. Also, in this case, we can use some parameters from matplotlib, such as
marker
,
markerfacecolor
, or
markersize
:
fig
=
plt
.
subplots
(
figsize
=
(
20
,
5
)
)
sns
.
lineplot
(
x
=
'Date'
,
y
=
'Euro rate'
,
data
=
usd
,
marker
=
'*'
,
markerfacecolor
=
'limegreen'
,
markersize
=
20
)
.
set
(
title
=
'Euro-USD rate'
,
xlabel
=
'Date'
,
ylabel
=
'Rate'
)
sns
.
set_theme
(
style
=
'white'
,
font_scale
=
3
)
Was this AI assistant helpful?
Output
:
The
documentation
provides us with the ultimate list of the parameters to use for improving the aesthetics of a seaborn line plot. In particular, we can see all the
possible choices of markers
.
In our
Seaborn cheat sheet
, you'll find other ways to customize a line plot in Seaborn.
Seaborn Line Plots With Multiple Lines
Often, we need to explore how several continuous variables change depending on another continuous variable. For this purpose, we can build a seaborn line plot with multiple lines. The functions
lineplot()
and
relplot()
are also applicable to such cases.
Creating a seaborn line plot with multiple lines
Technically, it's possible to create a seaborn line plot with multiple lines just by building a separate axes object for each dependent variable, i.e., each line:
aud
=
daily_exchange_rate_df
[
daily_exchange_rate_df
[
'Currency'
]
==
'Australian dollar'
]
.
reset_index
(
drop
=
True
)
cad
=
daily_exchange_rate_df
[
daily_exchange_rate_df
[
'Currency'
]
==
'Canadian dollar'
]
.
reset_index
(
drop
=
True
)
sns
.
lineplot
(
x
=
'Date'
,
y
=
'Euro rate'
,
data
=
usd
)
sns
.
lineplot
(
x
=
'Date'
,
y
=
'Euro rate'
,
data
=
aud
)
sns
.
lineplot
(
x
=
'Date'
,
y
=
'Euro rate'
,
data
=
cad
)
Output
:
Above, we extracted two more subsets from our initial dataframe
daily_exchange_rate_df
– for Australian and Canadian dollars – and plotted each euro rate against time. However, there are more efficient solutions to it: using the
hue
,
style
, or
size
parameters, available in both
lineplot()
and
relplot()
.
Using the hue parameter
This parameter works as follows: we assign to it the name of a dataframe column containing categorical values, and then seaborn generates a line plot for each category, giving a different color to each line:
sns
.
lineplot
(
x
=
'Date'
,
y
=
'Euro rate'
,
data
=
daily_exchange_rate_df
,
hue
=
'Currency'
)
Output
:
With just one line of simple code, we created a seaborn line plot for three categories. Note that we passed in the initial dataframe
daily_exchange_rate_df
instead of its subsets for different currencies.
Using the style parameter
The style parameter works in the same way as hue, only that it distinguishes between the categories by using different line styles (solid, dashed, dotted, etc.), without affecting the color:
sns
.
lineplot
(
x
=
'Date'
,
y
=
'Euro rate'
,
data
=
daily_exchange_rate_df
,
style
=
'Currency'
)
Output
:
Using the size parameter
Just like hue and style, the size parameter creates a separate line for each category. It doesn't affect the color and style of the lines but makes each of them of different width:
sns
.
lineplot
(
x
=
'Date'
,
y
=
'Euro rate'
,
data
=
daily_exchange_rate_df
,
size
=
'Currency'
)
Output
:
Customizing a seaborn line plot with multiple lines
Let's now experiment with the aesthetics of our graph. Some techniques here are identical to those we applied to a single Seaborn line plot. The others are specific only to line plots with multiple lines.
Overall adjustments
We can adjust the figure size, add a title and axis labels, and change the font size of the above graph in the same way as we did for a single line plot:
fig
=
plt
.
subplots
(
figsize
=
(
20
,
5
)
)
sns
.
lineplot
(
x
=
'Date'
,
y
=
'Euro rate'
,
data
=
daily_exchange_rate_df
,
hue
=
'Currency'
)
.
set
(
title
=
'Euro rates for different currencies'
,
xlabel
=
'Date'
,
ylabel
=
'Rate'
)
sns
.
set_theme
(
style
=
'white'
,
font_scale
=
3
)
Output
:
Changing the color, style, and size of each line
Earlier, we saw that when the hue, style, or size parameters are used, seaborn provides a default set of colors/styles/sizes for a line plot with multiple lines. If necessary, we can override these defaults and select colors/styles/sizes by ourselves.
When we use the hue parameter, we can also pass in the
palette
argument as a list or tuple of matplotlib color names. I would read our
tutorial,
Seaborn Color Palette: Quick Guide to Picking Colors
,
to understand more about color theory and to get lots of good ideas to make your visuals look nice.
fig
=
plt
.
subplots
(
figsize
=
(
20
,
5
)
)
sns
.
lineplot
(
x
=
'Date'
,
y
=
'Euro rate'
,
data
=
daily_exchange_rate_df
,
hue
=
'Currency'
,
palette
=
[
'magenta'
,
'deepskyblue'
,
'yellowgreen'
]
)
.
set
(
title
=
'Euro rates for different currencies'
,
xlabel
=
'Date'
,
ylabel
=
'Rate'
)
sns
.
set_theme
(
style
=
'white'
,
font_scale
=
3
)
Output
:
It's also possible to apply directly an existing matplotlib palette:
fig
=
plt
.
subplots
(
figsize
=
(
20
,
5
)
)
sns
.
lineplot
(
x
=
'Date'
,
y
=
'Euro rate'
,
data
=
daily_exchange_rate_df
,
hue
=
'Currency'
,
palette
=
'spring'
)
.
set
(
title
=
'Euro rates for different currencies'
,
xlabel
=
'Date'
,
ylabel
=
'Rate'
)
sns
.
set_theme
(
style
=
'white'
,
font_scale
=
3
)
Output
:
At the same time, when using
hue
, we can still adjust the line style and width of all the lines passing in the arguments
linestyle
and
linewidth
:
fig
=
plt
.
subplots
(
figsize
=
(
20
,
5
)
)
sns
.
lineplot
(
x
=
'Date'
,
y
=
'Euro rate'
,
data
=
daily_exchange_rate_df
,
hue
=
'Currency'
,
palette
=
[
'magenta'
,
'deepskyblue'
,
'yellowgreen'
]
,
linestyle
=
'dashed'
,
linewidth
=
5
)
.
set
(
title
=
'Euro rates for different currencies'
,
xlabel
=
'Date'
,
ylabel
=
'Rate'
)
sns
.
set_theme
(
style
=
'white'
,
font_scale
=
3
)
Output
:
Instead, when we create a seaborn line plot with multiple lines using the style parameter, we can assign a list (or a tuple) of lists (or tuples) to a parameter called dashes:
fig
=
plt
.
subplots
(
figsize
=
(
20
,
5
)
)
sns
.
lineplot
(
x
=
'Date'
,
y
=
'Euro rate'
,
data
=
daily_exchange_rate_df
,
style
=
'Currency'
,
dashes
=
[
[
4
,
4
]
,
[
6
,
1
]
,
[
3
,
9
]
]
)
.
set
(
title
=
'Euro rates for different currencies'
,
xlabel
=
'Date'
,
ylabel
=
'Rate'
)
sns
.
set_theme
(
style
=
'white'
,
font_scale
=
3
)
Output
:
In the above list of lists assigned to dashes, the first item of each sublist represents the length of a segment of the corresponding line, while the second item – the length of a gap.
Note: to represent a solid line, we need to set the length of a gap to zero, e.g.:
[1, 0]
.
To adjust the color and width of all the lines of this graph, we provide the arguments color and linewidth, just like we did when customizing a single seaborn line plot:
fig
=
plt
.
subplots
(
figsize
=
(
20
,
5
)
)
sns
.
lineplot
(
x
=
'Date'
,
y
=
'Euro rate'
,
data
=
daily_exchange_rate_df
,
style
=
'Currency'
,
dashes
=
[
[
4
,
4
]
,
[
6
,
1
]
,
[
3
,
9
]
]
,
color
=
'darkviolet'
,
linewidth
=
4
)
.
set
(
title
=
'Euro rates for different currencies'
,
xlabel
=
'Date'
,
ylabel
=
'Rate'
)
sns
.
set_theme
(
style
=
'white'
,
font_scale
=
3
)
Output
:
Finally, when we use the size parameter to create a seaborn multiple line plot, we can regulate the width of each line through the
sizes
parameter. It takes in a list (or a tuple) of integers:
fig
=
plt
.
subplots
(
figsize
=
(
20
,
5
)
)
sns
.
lineplot
(
x
=
'Date'
,
y
=
'Euro rate'
,
data
=
daily_exchange_rate_df
,
size
=
'Currency'
,
sizes
=
[
2
,
10
,
5
]
)
.
set
(
title
=
'Euro rates for different currencies'
,
xlabel
=
'Date'
,
ylabel
=
'Rate'
)
sns
.
set_theme
(
style
=
'white'
,
font_scale
=
3
)
Output
:
To customize the color and style of all the lines of this plot, we need to provide the arguments linestyle and color:
fig
=
plt
.
subplots
(
figsize
=
(
20
,
5
)
)
sns
.
lineplot
(
x
=
'Date'
,
y
=
'Euro rate'
,
data
=
daily_exchange_rate_df
,
size
=
'Currency'
,
sizes
=
[
2
,
10
,
5
]
,
linestyle
=
'dotted'
,
color
=
'teal'
)
.
set
(
title
=
'Euro rates for different currencies'
,
xlabel
=
'Date'
,
ylabel
=
'Rate'
)
sns
.
set_theme
(
style
=
'white'
,
font_scale
=
3
)
Output
:
Adding markers and customizing their color, style, and size
We may want to add markers on our seaborn multiple line plot.
To add markers of the same color, style, and size on all the lines, we need to use the parameters from matplotlib, such as marker,
markerfacecolor
,
markersize
, etc., just as we did for a single line plot:
fig
=
plt
.
subplots
(
figsize
=
(
20
,
5
)
)
sns
.
lineplot
(
x
=
'Date'
,
y
=
'Euro rate'
,
data
=
daily_exchange_rate_df
,
hue
=
'Currency'
,
marker
=
'o'
,
markerfacecolor
=
'orangered'
,
markersize
=
10
)
.
set
(
title
=
'Euro rates for different currencies'
,
xlabel
=
'Date'
,
ylabel
=
'Rate'
)
sns
.
set_theme
(
style
=
'white'
,
font_scale
=
3
)
Output
:
Things are different, though, when we want different markers for each line. In this case, we need to use the markers parameter, which, however, according to seaborn functionalities, works only when the style parameter is specified:
fig
=
plt
.
subplots
(
figsize
=
(
20
,
5
)
)
sns
.
lineplot
(
x
=
'Date'
,
y
=
'Euro rate'
,
data
=
daily_exchange_rate_df
,
style
=
'Currency'
,
markers
=
[
'o'
,
'X'
,
'*'
]
,
markerfacecolor
=
'brown'
,
markersize
=
10
)
.
set
(
title
=
'Euro rates for different currencies'
,
xlabel
=
'Date'
,
ylabel
=
'Rate'
)
sns
.
set_theme
(
style
=
'white'
,
font_scale
=
3
)
Output
:
On the above plot, we can make all the lines solid by providing the dashes argument and setting the
[1, 0]
style pattern to each line:
fig
=
plt
.
subplots
(
figsize
=
(
20
,
5
)
)
sns
.
lineplot
(
x
=
'Date'
,
y
=
'Euro rate'
,
data
=
daily_exchange_rate_df
,
style
=
'Currency'
,
markers
=
[
'o'
,
'X'
,
'*'
]
,
dashes
=
[
[
1
,
0
]
,
[
1
,
0
]
,
[
1
,
0
]
]
,
markerfacecolor
=
'brown'
,
markersize
=
10
)
.
set
(
title
=
'Euro rates for different currencies'
,
xlabel
=
'Date'
,
ylabel
=
'Rate'
)
sns
.
set_theme
(
style
=
'white'
,
font_scale
=
3
)
Output
:
Conclusion
To recap, in this tutorial, we learned a range of ways to create and customize a Seaborn line plot with either a single or multiple lines.
As a way forward, with seaborn, we can do much more to further adjust a line plot. For example, we can:
Group lines by more than one categorical variable
Customize the legend
Create line plots with multiple lines on different facets
Display and customize the confidence interval
Customize time axis ticks and their labels for a time series line plot
To dig deeper into what and how can be done with seaborn, consider taking our course
Intermediate Data Visualization with Seaborn
. |
| Markdown | [ Build job-ready data + AI skills. Save **50%** today Buy Now](https://www.datacamp.com/promo/flash-sale-apr-26)
[Skip to main content](https://www.datacamp.com/tutorial/python-seaborn-line-plot-tutorial#main)
EN
[English](https://www.datacamp.com/tutorial/python-seaborn-line-plot-tutorial)[Español](https://www.datacamp.com/es/tutorial/python-seaborn-line-plot-tutorial)[Português](https://www.datacamp.com/pt/tutorial/python-seaborn-line-plot-tutorial)[DeutschBeta](https://www.datacamp.com/de/tutorial/python-seaborn-line-plot-tutorial)[FrançaisBeta](https://www.datacamp.com/fr/tutorial/python-seaborn-line-plot-tutorial)[ItalianoBeta](https://www.datacamp.com/it/tutorial/python-seaborn-line-plot-tutorial)[TürkçeBeta](https://www.datacamp.com/tr/tutorial/python-seaborn-line-plot-tutorial)[Bahasa IndonesiaBeta](https://www.datacamp.com/id/tutorial/python-seaborn-line-plot-tutorial)[Tiếng ViệtBeta](https://www.datacamp.com/vi/tutorial/python-seaborn-line-plot-tutorial)[NederlandsBeta](https://www.datacamp.com/nl/tutorial/python-seaborn-line-plot-tutorial)[हिन्दीBeta](https://www.datacamp.com/hi/tutorial/python-seaborn-line-plot-tutorial)[日本語Beta](https://www.datacamp.com/ja/tutorial/python-seaborn-line-plot-tutorial)[한국어Beta](https://www.datacamp.com/ko/tutorial/python-seaborn-line-plot-tutorial)[PolskiBeta](https://www.datacamp.com/pl/tutorial/python-seaborn-line-plot-tutorial)[RomânăBeta](https://www.datacamp.com/ro/tutorial/python-seaborn-line-plot-tutorial)[РусскийBeta](https://www.datacamp.com/ru/tutorial/python-seaborn-line-plot-tutorial)[SvenskaBeta](https://www.datacamp.com/sv/tutorial/python-seaborn-line-plot-tutorial)[ไทยBeta](https://www.datacamp.com/th/tutorial/python-seaborn-line-plot-tutorial)[中文(简体)Beta](https://www.datacamp.com/zh/tutorial/python-seaborn-line-plot-tutorial)
***
[More Information](https://support.datacamp.com/hc/en-us/articles/21821832799255-Languages-Available-on-DataCamp)
[Found an Error?]()
[Log in](https://www.datacamp.com/users/sign_in?redirect=%2Ftutorial%2Fpython-seaborn-line-plot-tutorial)[Get Started](https://www.datacamp.com/users/sign_up?redirect=%2Ftutorial%2Fpython-seaborn-line-plot-tutorial)
Tutorials
[Blogs](https://www.datacamp.com/blog)
[Tutorials](https://www.datacamp.com/tutorial)
[docs](https://www.datacamp.com/doc)
[Podcasts](https://www.datacamp.com/podcast)
[Cheat Sheets](https://www.datacamp.com/cheat-sheet)
[code-alongs](https://www.datacamp.com/code-along)
[Newsletter](https://dcthemedian.substack.com/)
Category
Category
Technologies
Discover content by tools and technology
[AI Agents](https://www.datacamp.com/tutorial/category/ai-agents)[AI News](https://www.datacamp.com/tutorial/category/ai-news)[Artificial Intelligence](https://www.datacamp.com/tutorial/category/ai)[AWS](https://www.datacamp.com/tutorial/category/aws)[Azure](https://www.datacamp.com/tutorial/category/microsoft-azure)[Business Intelligence](https://www.datacamp.com/tutorial/category/learn-business-intelligence)[ChatGPT](https://www.datacamp.com/tutorial/category/chatgpt)[Databricks](https://www.datacamp.com/tutorial/category/databricks)[dbt](https://www.datacamp.com/tutorial/category/dbt)[Docker](https://www.datacamp.com/tutorial/category/docker)[Excel](https://www.datacamp.com/tutorial/category/excel)[Generative AI](https://www.datacamp.com/tutorial/category/generative-ai)[Git](https://www.datacamp.com/tutorial/category/git)[Google Cloud Platform](https://www.datacamp.com/tutorial/category/google-cloud-platform)[Hugging Face](https://www.datacamp.com/tutorial/category/Hugging-Face)[Java](https://www.datacamp.com/tutorial/category/java)[Julia](https://www.datacamp.com/tutorial/category/julia)[Kafka](https://www.datacamp.com/tutorial/category/apache-kafka)[Kubernetes](https://www.datacamp.com/tutorial/category/kubernetes)[Large Language Models](https://www.datacamp.com/tutorial/category/large-language-models)[MongoDB](https://www.datacamp.com/tutorial/category/mongodb)[MySQL](https://www.datacamp.com/tutorial/category/mysql)[NoSQL](https://www.datacamp.com/tutorial/category/nosql)[OpenAI](https://www.datacamp.com/tutorial/category/OpenAI)[PostgreSQL](https://www.datacamp.com/tutorial/category/postgresql)[Power BI](https://www.datacamp.com/tutorial/category/power-bi)[PySpark](https://www.datacamp.com/tutorial/category/pyspark)[Python](https://www.datacamp.com/tutorial/category/python)[R](https://www.datacamp.com/tutorial/category/r-programming)[Scala](https://www.datacamp.com/tutorial/category/scala)[Snowflake](https://www.datacamp.com/tutorial/category/snowflake)[Spreadsheets](https://www.datacamp.com/tutorial/category/spreadsheets)[SQL](https://www.datacamp.com/tutorial/category/sql)[SQLite](https://www.datacamp.com/tutorial/category/sqlite)[Tableau](https://www.datacamp.com/tutorial/category/tableau)
Category
Topics
Discover content by data science topics
[AI for Business](https://www.datacamp.com/tutorial/category/ai-for-business)[Big Data](https://www.datacamp.com/tutorial/category/big-data)[Career Services](https://www.datacamp.com/tutorial/category/career-services)[Cloud](https://www.datacamp.com/tutorial/category/cloud)[Data Analysis](https://www.datacamp.com/tutorial/category/data-analysis)[Data Engineering](https://www.datacamp.com/tutorial/category/data-engineering)[Data Literacy](https://www.datacamp.com/tutorial/category/data-literacy)[Data Science](https://www.datacamp.com/tutorial/category/data-science)[Data Visualization](https://www.datacamp.com/tutorial/category/data-visualization)[DataLab](https://www.datacamp.com/tutorial/category/datalab)[Deep Learning](https://www.datacamp.com/tutorial/category/deep-learning)[Machine Learning](https://www.datacamp.com/tutorial/category/machine-learning)[MLOps](https://www.datacamp.com/tutorial/category/mlops)[Natural Language Processing](https://www.datacamp.com/tutorial/category/natural-language-processing)[Vector Databases](https://www.datacamp.com/tutorial/category/vector-databases)
[Browse Courses](https://www.datacamp.com/courses-all)
category
1. [Home](https://www.datacamp.com/)
2. [Tutorials](https://www.datacamp.com/tutorial)
3. [Python](https://www.datacamp.com/tutorial/category/python)
# Python Seaborn Line Plot Tutorial: Create Data Visualizations
Discover how to use Seaborn, a popular Python data visualization library, to create and customize line plots in Python.
Contents
Updated Dec 9, 2024 · 12 min read
Contents
- [Introducing the Dataset](https://www.datacamp.com/tutorial/python-seaborn-line-plot-tutorial#introducing-the-dataset-tohav)
- [Seaborn Line Plot Basics](https://www.datacamp.com/tutorial/python-seaborn-line-plot-tutorial#seaborn-line-plot-basics-tocre)
- [Creating a single seaborn line plot](https://www.datacamp.com/tutorial/python-seaborn-line-plot-tutorial#creating-a-single-seaborn-line-plot-wecan)
- [Customizing a single seaborn line plot](https://www.datacamp.com/tutorial/python-seaborn-line-plot-tutorial#customizing-a-single-seaborn-line-plot-wecan)
- [Adjusting the figure size](https://www.datacamp.com/tutorial/python-seaborn-line-plot-tutorial#adjusting-the-figure-size-since)
- [Adding a title and axis labels](https://www.datacamp.com/tutorial/python-seaborn-line-plot-tutorial#adding-a-title-and-axis-labels-toadd)
- [Adjusting the font size](https://www.datacamp.com/tutorial/python-seaborn-line-plot-tutorial#adjusting-the-font-size-aconv)
- [Changing the line color, style, and size](https://www.datacamp.com/tutorial/python-seaborn-line-plot-tutorial#changing-the-line-color,-style,-and-size-tocus)
- [Adding markers and customizing their color, style, and size](https://www.datacamp.com/tutorial/python-seaborn-line-plot-tutorial#adding-markers-and-customizing-their-color,-style,-and-size-it'sp)
- [Seaborn Line Plots With Multiple Lines](https://www.datacamp.com/tutorial/python-seaborn-line-plot-tutorial#seaborn-line-plots-with-multiple-lines-often)
- [Creating a seaborn line plot with multiple lines](https://www.datacamp.com/tutorial/python-seaborn-line-plot-tutorial#creating-a-seaborn-line-plot-with-multiple-lines-techn)
- [Using the hue parameter](https://www.datacamp.com/tutorial/python-seaborn-line-plot-tutorial#using-the-hue-parameter-thisp)
- [Using the style parameter](https://www.datacamp.com/tutorial/python-seaborn-line-plot-tutorial#using-the-style-parameter-thest)
- [Using the size parameter](https://www.datacamp.com/tutorial/python-seaborn-line-plot-tutorial#using-the-size-parameter-justl)
- [Customizing a seaborn line plot with multiple lines](https://www.datacamp.com/tutorial/python-seaborn-line-plot-tutorial#customizing-a-seaborn-line-plot-with-multiple-lines-let's)
- [Overall adjustments](https://www.datacamp.com/tutorial/python-seaborn-line-plot-tutorial#overall-adjustments-wecan)
- [Changing the color, style, and size of each line](https://www.datacamp.com/tutorial/python-seaborn-line-plot-tutorial#changing-the-color,-style,-and-size-of-each-line-earli)
- [Adding markers and customizing their color, style, and size](https://www.datacamp.com/tutorial/python-seaborn-line-plot-tutorial#adding-markers-and-customizing-their-color,-style,-and-size-wemay)
- [Conclusion](https://www.datacamp.com/tutorial/python-seaborn-line-plot-tutorial#conclusion-torec)
- [Seaborn Line Plot FAQs](https://www.datacamp.com/tutorial/python-seaborn-line-plot-tutorial#faq)
## Training more people?
Get your team access to the full DataCamp for business platform.
[For Business](https://www.datacamp.com/business)For a bespoke solution [book a demo](https://www.datacamp.com/business/demo-2).
A line plot is a relational data visualization showing how one continuous variable changes when another does. It's one of the most common graphs widely used in finance, sales, marketing, healthcare, natural sciences, and more.
In this tutorial, we'll discuss how to use Seaborn, a popular Python data visualization library, to create and customize line plots in Python.
## Introducing the Dataset
To have something to practice seaborn line plots on, we'll first download a Kaggle dataset called [Daily Exchange Rates per Euro 1999-2024](https://www.kaggle.com/datasets/lsind18/euro-exchange-daily-rates-19992020). Then, we'll import all the necessary packages and read in and clean the dataframe. Without getting into details of the cleaning process, the code below demonstrates the steps to perform:
```
Powered By
```
**Output**:
```
Powered ByWas this AI assistant helpful? Yes No
```
The resulting dataframe contains daily (business days) Euro rates for Australian, Canadian, and US dollars for the period from `01.12.2022` until `27.01.2023` inclusive.
Now, we're ready to dive into creating and customizing Python seaborn line plots.
## Seaborn Line Plot Basics
To create a line plot in Seaborn, we can use one of the two functions: `lineplot()` or `relplot()`. Overall, they have a lot of functionality in common, together with identical parameter names. The main difference is that `relplot()` allows us to create line plots with multiple lines on different facets. Instead, `lineplot()` allows working with confidence intervals and data aggregation.
In this tutorial, we'll mostly use the `lineplot()` function.
The course [Introduction to Data Visualization with Seaborn](https://www.datacamp.com/courses/introduction-to-data-visualization-with-seaborn) will help you learn and practice the main functions and methods of the seaborn library. You can also check out our [Seaborn tutorial for beginners](https://www.datacamp.com/tutorial/seaborn-python-tutorial) to get more familiar with the popular Python library.
### Creating a single seaborn line plot
We can create a line plot showing the relationships between two continuous variables as follows:
```
Powered By
```
**Output**:

The above graph shows the EUR-USD rate dynamics. We defined the variables to plot on the *x* and *y* axes (the *x* and *y* parameters) and the dataframe (data) to take these variables from.
For comparison, to create the same plot using `relplot()`, we would write the following:
```
sns.relplot(x='Date', y='Euro rate', data=usd, kind='line')Powered ByWas this AI assistant helpful? Yes No
```
**Output**:

In this case, we passed in one more argument specific to the `relplot()` function: `kind='line'`. By default, this function creates a scatter plot.
### Customizing a single seaborn line plot
We can customize the above chart in many ways to make it more readable and informative. For example, we can adjust the figure size, add title and axis labels, adjust the font size, customize the line, add and customize markers, etc. Let's see how to implement these improvements in seaborn.
#### Adjusting the figure size
Since Seaborn is built on top of matplotlib, we can use `matplotlib.pyplot` to adjust the figure size:
```
Powered ByWas this AI assistant helpful? Yes No
```
**Output**:

Instead, with relplot(), we can use the height and aspect (the width-to-height ratio) parameters for the same purpose:
```
sns.relplot(x='Date', y='Euro rate', data=usd, kind='line', height=6, aspect=4)Powered ByWas this AI assistant helpful? Yes No
```
**Output**:

#### Adding a title and axis labels
To add a graph title and axis labels, we can use the `set()` function on the seaborn line plot object passing in the title, `xlabel`, and `ylabel` arguments:
```
Powered ByWas this AI assistant helpful? Yes No
```
**Output**:

#### Adjusting the font size
A convenient way to adjust the font size is to use the `set_theme()` function and experiment with different values of the `font_scale` parameter:
```
Powered ByWas this AI assistant helpful? Yes No
```
**Output**:

Note that we also added `style='white'` to avoid overriding the initial style.
#### Changing the line color, style, and size
To customize the plot line, we can pass in some optional parameters in common with `matplotlib.pyplot.plot`, such as `color`, `linestyle`, or `linewidth`:
```
Powered ByWas this AI assistant helpful? Yes No
```
**Output**:

#### Adding markers and customizing their color, style, and size
It's possible to add markers on the line and customize their appearance. Also, in this case, we can use some parameters from matplotlib, such as `marker`, `markerfacecolor`, or `markersize`:
```
Powered ByWas this AI assistant helpful? Yes No
```
**Output**:

The [documentation](https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.plot.html) provides us with the ultimate list of the parameters to use for improving the aesthetics of a seaborn line plot. In particular, we can see all the [possible choices of markers](https://matplotlib.org/stable/api/markers_api.html#module-matplotlib.markers).
In our [Seaborn cheat sheet](https://www.datacamp.com/resources/cheat-sheets/python-seaborn-cheat-sheet), you'll find other ways to customize a line plot in Seaborn.
## Seaborn Line Plots With Multiple Lines
Often, we need to explore how several continuous variables change depending on another continuous variable. For this purpose, we can build a seaborn line plot with multiple lines. The functions `lineplot()` and `relplot()` are also applicable to such cases.
### Creating a seaborn line plot with multiple lines
Technically, it's possible to create a seaborn line plot with multiple lines just by building a separate axes object for each dependent variable, i.e., each line:
```
Powered By
```
**Output**:

Above, we extracted two more subsets from our initial dataframe `daily_exchange_rate_df` – for Australian and Canadian dollars – and plotted each euro rate against time. However, there are more efficient solutions to it: using the `hue`, `style`, or `size` parameters, available in both `lineplot()` and `relplot()`.
#### Using the hue parameter
This parameter works as follows: we assign to it the name of a dataframe column containing categorical values, and then seaborn generates a line plot for each category, giving a different color to each line:
```
sns.lineplot(x='Date', y='Euro rate', data=daily_exchange_rate_df, hue='Currency')Powered By
```
**Output**:

With just one line of simple code, we created a seaborn line plot for three categories. Note that we passed in the initial dataframe `daily_exchange_rate_df` instead of its subsets for different currencies.
#### Using the style parameter
The style parameter works in the same way as hue, only that it distinguishes between the categories by using different line styles (solid, dashed, dotted, etc.), without affecting the color:
```
sns.lineplot(x='Date', y='Euro rate', data=daily_exchange_rate_df, style='Currency')Powered By
```
**Output**:

#### Using the size parameter
Just like hue and style, the size parameter creates a separate line for each category. It doesn't affect the color and style of the lines but makes each of them of different width:
```
sns.lineplot(x='Date', y='Euro rate', data=daily_exchange_rate_df, size='Currency')Powered By
```
**Output**:

### Customizing a seaborn line plot with multiple lines
Let's now experiment with the aesthetics of our graph. Some techniques here are identical to those we applied to a single Seaborn line plot. The others are specific only to line plots with multiple lines.
#### Overall adjustments
We can adjust the figure size, add a title and axis labels, and change the font size of the above graph in the same way as we did for a single line plot:
```
Powered By
```
**Output**:

#### Changing the color, style, and size of each line
Earlier, we saw that when the hue, style, or size parameters are used, seaborn provides a default set of colors/styles/sizes for a line plot with multiple lines. If necessary, we can override these defaults and select colors/styles/sizes by ourselves.
When we use the hue parameter, we can also pass in the `palette` argument as a list or tuple of matplotlib color names. I would read our tutorial, [Seaborn Color Palette: Quick Guide to Picking Colors](https://www.datacamp.com/tutorial/seaborn-palettes), to understand more about color theory and to get lots of good ideas to make your visuals look nice.
```
Powered By
```
**Output**:

It's also possible to apply directly an existing matplotlib palette:
```
Powered By
```
**Output**:

At the same time, when using `hue`, we can still adjust the line style and width of all the lines passing in the arguments `linestyle` and `linewidth`:
```
Powered By
```
**Output**:

Instead, when we create a seaborn line plot with multiple lines using the style parameter, we can assign a list (or a tuple) of lists (or tuples) to a parameter called dashes:
```
Powered By
```
**Output**:

In the above list of lists assigned to dashes, the first item of each sublist represents the length of a segment of the corresponding line, while the second item – the length of a gap.
Note: to represent a solid line, we need to set the length of a gap to zero, e.g.: `[1, 0]`.
To adjust the color and width of all the lines of this graph, we provide the arguments color and linewidth, just like we did when customizing a single seaborn line plot:
```
Powered By
```
**Output**:

Finally, when we use the size parameter to create a seaborn multiple line plot, we can regulate the width of each line through the `sizes` parameter. It takes in a list (or a tuple) of integers:
```
Powered By
```
**Output**:

To customize the color and style of all the lines of this plot, we need to provide the arguments linestyle and color:
```
Powered By
```
**Output**:

#### Adding markers and customizing their color, style, and size
We may want to add markers on our seaborn multiple line plot.
To add markers of the same color, style, and size on all the lines, we need to use the parameters from matplotlib, such as marker, `markerfacecolor`, `markersize`, etc., just as we did for a single line plot:
```
Powered By
```
**Output**:

Things are different, though, when we want different markers for each line. In this case, we need to use the markers parameter, which, however, according to seaborn functionalities, works only when the style parameter is specified:
```
Powered By
```
**Output**:

On the above plot, we can make all the lines solid by providing the dashes argument and setting the `[1, 0]` style pattern to each line:
```
Powered By
```
**Output**:

## Conclusion
To recap, in this tutorial, we learned a range of ways to create and customize a Seaborn line plot with either a single or multiple lines.
As a way forward, with seaborn, we can do much more to further adjust a line plot. For example, we can:
- Group lines by more than one categorical variable
- Customize the legend
- Create line plots with multiple lines on different facets
- Display and customize the confidence interval
- Customize time axis ticks and their labels for a time series line plot
To dig deeper into what and how can be done with seaborn, consider taking our course [Intermediate Data Visualization with Seaborn](https://www.datacamp.com/courses/intermediate-data-visualization-with-seaborn).
## Seaborn Line Plot FAQs
### What is a line plot in Seaborn?
A line plot is a type of plot in Seaborn that shows the relationship between two variables by connecting the data points with a straight line.
### What kind of data is best suited for a line plot in Seaborn?
Line plots are best suited for data where there is a clear relationship between two variables, and where the variables are continuous or ordinal.
### Can I plot multiple lines on the same plot in Seaborn?
Yes, you can plot multiple lines on the same plot in Seaborn by using the `hue` parameter to specify a categorical variable to group the data by.
### What is the difference between a line plot and a scatter plot in Seaborn?
A line plot in Seaborn shows the relationship between two variables with a straight line, while a scatter plot shows the relationship with individual data points.
### Can I add a regression line to my line plot in Seaborn?
Yes, you can add a regression line to your line plot in Seaborn by using the `regplot()` function, which fits and plots a linear regression model between two variables.
### How do I save my Seaborn line plot to a file?
You can save your Seaborn line plot to a file by using the `savefig()` function from the `matplotlib` library, which saves the current figure to a specified file path and format.
Topics
[Python](https://www.datacamp.com/tutorial/category/python)
[Data Visualization](https://www.datacamp.com/tutorial/category/data-visualization)
***
[Elena Kosourova](https://www.datacamp.com/portfolio/evkosourova)IBM Certified Data Scientist proficient in Python, R, SQL, data analysis, and machine learning
***
Topics
[Python](https://www.datacamp.com/tutorial/category/python)
[Data Visualization](https://www.datacamp.com/tutorial/category/data-visualization)

[Python Seaborn Cheat Sheet](https://www.datacamp.com/cheat-sheet/python-seaborn-cheat-sheet)
[Python Seaborn Tutorial For Beginners: Start Visualizing Data](https://www.datacamp.com/tutorial/seaborn-python-tutorial)

[Introduction to Plotting with Matplotlib in Python](https://www.datacamp.com/tutorial/matplotlib-tutorial-python)
[Seaborn Heatmaps: A Guide to Data Visualization](https://www.datacamp.com/tutorial/seaborn-heatmaps)

[How to Make a Seaborn Histogram: A Detailed Guide](https://www.datacamp.com/tutorial/how-to-make-a-seaborn-histogram)
[Matplotlib time series line plot](https://www.datacamp.com/tutorial/matplotlib-time-series-line-plot)
Related

[cheat-sheetPython Seaborn Cheat Sheet](https://www.datacamp.com/cheat-sheet/python-seaborn-cheat-sheet)
This Python Seaborn cheat sheet with code samples guides you through the data visualization library that is based on Matplotlib.
Karlijn Willems
[TutorialPython Seaborn Tutorial For Beginners: Start Visualizing Data](https://www.datacamp.com/tutorial/seaborn-python-tutorial)
This Seaborn tutorial introduces you to the basics of statistical data visualization
Moez Ali

[TutorialIntroduction to Plotting with Matplotlib in Python](https://www.datacamp.com/tutorial/matplotlib-tutorial-python)
This tutorial demonstrates how to use Matplotlib, a powerful data visualization library in Python, to create line, bar, and scatter plots with stock market data.
Kevin Babitz
[TutorialSeaborn Heatmaps: A Guide to Data Visualization](https://www.datacamp.com/tutorial/seaborn-heatmaps)
Learn how to create eye-catching Seaborn heatmaps.
[](https://www.datacamp.com/portfolio/joleen-bothma)
Joleen Bothma

[TutorialHow to Make a Seaborn Histogram: A Detailed Guide](https://www.datacamp.com/tutorial/how-to-make-a-seaborn-histogram)
Find out how to create a histogram chart using the Seaborn library in Python.
Austin Chia
[TutorialMatplotlib time series line plot](https://www.datacamp.com/tutorial/matplotlib-time-series-line-plot)
This tutorial explores how to create and customize time series line plots in matplotlib.
[](https://www.datacamp.com/portfolio/evkosourova)
Elena Kosourova
[See More](https://www.datacamp.com/tutorial/category/python)
[See More](https://www.datacamp.com/tutorial/category/python)
## Grow your data skills with DataCamp for Mobile
Make progress on the go with our mobile courses and daily 5-minute coding challenges.
[Download on the App Store](https://datacamp.onelink.me/xztQ/45dozwue?deep_link_sub1=%7B%22src_url%22%3A%22https%3A%2F%2Fwww.datacamp.com%2Ftutorial%2Fpython-seaborn-line-plot-tutorial%22%7D)[Get it on Google Play](https://datacamp.onelink.me/xztQ/go2f19ij?deep_link_sub1=%7B%22src_url%22%3A%22https%3A%2F%2Fwww.datacamp.com%2Ftutorial%2Fpython-seaborn-line-plot-tutorial%22%7D)
**Learn**
[Learn Python](https://www.datacamp.com/blog/how-to-learn-python-expert-guide)[Learn AI](https://www.datacamp.com/blog/how-to-learn-ai)[Learn Power BI](https://www.datacamp.com/learn/power-bi)[Learn Data Engineering](https://www.datacamp.com/category/data-engineering)[Assessments](https://www.datacamp.com/signal)[Career Tracks](https://www.datacamp.com/tracks/career)[Skill Tracks](https://www.datacamp.com/tracks/skill)[Courses](https://www.datacamp.com/courses-all)[Data Science Roadmap](https://www.datacamp.com/blog/data-science-roadmap)
**Data Courses**
[Python Courses](https://www.datacamp.com/category/python)[R Courses](https://www.datacamp.com/category/r)[SQL Courses](https://www.datacamp.com/category/sql)[Power BI Courses](https://www.datacamp.com/category/power-bi)[Tableau Courses](https://www.datacamp.com/category/tableau)[Alteryx Courses](https://www.datacamp.com/category/alteryx)[Azure Courses](https://www.datacamp.com/category/azure)[AWS Courses](https://www.datacamp.com/category/aws)[Google Cloud Courses](https://www.datacamp.com/category/google-cloud)[Google Sheets Courses](https://www.datacamp.com/category/google-sheets)[Excel Courses](https://www.datacamp.com/category/excel)[AI Courses](https://www.datacamp.com/category/artificial-intelligence)[Data Analysis Courses](https://www.datacamp.com/category/data-analysis)[Data Visualization Courses](https://www.datacamp.com/category/data-visualization)[Machine Learning Courses](https://www.datacamp.com/category/machine-learning)[Data Engineering Courses](https://www.datacamp.com/category/data-engineering)[Probability & Statistics Courses](https://www.datacamp.com/category/probability-and-statistics)
**DataLab**
[Get Started](https://www.datacamp.com/datalab)[Pricing](https://www.datacamp.com/datalab/pricing)[Security](https://www.datacamp.com/datalab/security)[Documentation](https://datalab-docs.datacamp.com/)
**Certification**
[Certifications](https://www.datacamp.com/certification)[Data Scientist](https://www.datacamp.com/certification/data-scientist)[Data Analyst](https://www.datacamp.com/certification/data-analyst)[Data Engineer](https://www.datacamp.com/certification/data-engineer)[SQL Associate](https://www.datacamp.com/certification/sql-associate)[Power BI Data Analyst](https://www.datacamp.com/certification/data-analyst-in-power-bi)[Tableau Certified Data Analyst](https://www.datacamp.com/certification/data-analyst-in-tableau)[Azure Fundamentals](https://www.datacamp.com/certification/azure-fundamentals)[AI Fundamentals](https://www.datacamp.com/certification/ai-fundamentals)
**Resources**
[Resource Center](https://www.datacamp.com/resources)[Upcoming Events](https://www.datacamp.com/webinars)[Blog](https://www.datacamp.com/blog)[Code-Alongs](https://www.datacamp.com/code-along)[Tutorials](https://www.datacamp.com/tutorial)[Docs](https://www.datacamp.com/doc)[Open Source](https://www.datacamp.com/open-source)[RDocumentation](https://www.rdocumentation.org/)[Book a Demo with DataCamp for Business](https://www.datacamp.com/business/demo)[Data Portfolio](https://www.datacamp.com/data-portfolio)
**Plans**
[Pricing](https://www.datacamp.com/pricing)[For Students](https://www.datacamp.com/pricing/student)[For Business](https://www.datacamp.com/business)[For Universities](https://www.datacamp.com/universities)[Discounts, Promos & Sales](https://www.datacamp.com/promo)[Expense DataCamp](https://www.datacamp.com/expense)[DataCamp Donates](https://www.datacamp.com/donates)
**For Business**
[Business Pricing](https://www.datacamp.com/business/compare-plans)[Teams Plan](https://www.datacamp.com/business/learn-teams)[Data & AI Unlimited Plan](https://www.datacamp.com/business/data-unlimited)[Customer Stories](https://www.datacamp.com/business/customer-stories)[Partner Program](https://www.datacamp.com/business/partner-program)
**About**
[About Us](https://www.datacamp.com/about)[Learner Stories](https://www.datacamp.com/stories)[Careers](https://www.datacamp.com/careers)[Become an Instructor](https://www.datacamp.com/learn/create)[Press](https://www.datacamp.com/press)[Leadership](https://www.datacamp.com/about/leadership)[Contact Us](https://support.datacamp.com/hc/en-us/articles/360021185634)[DataCamp Español](https://www.datacamp.com/es)[DataCamp Português](https://www.datacamp.com/pt)[DataCamp Deutsch](https://www.datacamp.com/de)[DataCamp Français](https://www.datacamp.com/fr)
**Support**
[Help Center](https://support.datacamp.com/hc/en-us)[Become an Affiliate](https://www.datacamp.com/affiliates)
[Facebook](https://www.facebook.com/datacampinc/)
[Twitter](https://twitter.com/datacamp)
[LinkedIn](https://www.linkedin.com/school/datacampinc/)
[YouTube](https://www.youtube.com/channel/UC79Gv3mYp6zKiSwYemEik9A)
[Instagram](https://www.instagram.com/datacamp/)
[Privacy Policy](https://www.datacamp.com/privacy-policy)[Cookie Notice](https://www.datacamp.com/cookie-notice)[Do Not Sell My Personal Information](https://www.datacamp.com/do-not-sell-my-personal-information)[Accessibility](https://www.datacamp.com/accessibility)[Security](https://www.datacamp.com/security)[Terms of Use](https://www.datacamp.com/terms-of-use)
© 2026 DataCamp, Inc. All Rights Reserved. |
| Readable Markdown | A line plot is a relational data visualization showing how one continuous variable changes when another does. It's one of the most common graphs widely used in finance, sales, marketing, healthcare, natural sciences, and more. In this tutorial, we'll discuss how to use Seaborn, a popular Python data visualization library, to create and customize line plots in Python. Introducing the Dataset To have something to practice seaborn line plots on, we'll first download a Kaggle dataset called [Daily Exchange Rates per Euro 1999-2024](https://www.kaggle.com/datasets/lsind18/euro-exchange-daily-rates-19992020). Then, we'll import all the necessary packages and read in and clean the dataframe. Without getting into details of the cleaning process, the code below demonstrates the steps to perform: **Output**: The resulting dataframe contains daily (business days) Euro rates for Australian, Canadian, and US dollars for the period from `01.12.2022` until `27.01.2023` inclusive. Now, we're ready to dive into creating and customizing Python seaborn line plots. Seaborn Line Plot Basics To create a line plot in Seaborn, we can use one of the two functions: `lineplot()` or `relplot()`. Overall, they have a lot of functionality in common, together with identical parameter names. The main difference is that `relplot()` allows us to create line plots with multiple lines on different facets. Instead, `lineplot()` allows working with confidence intervals and data aggregation. In this tutorial, we'll mostly use the `lineplot()` function. The course [Introduction to Data Visualization with Seaborn](https://www.datacamp.com/courses/introduction-to-data-visualization-with-seaborn) will help you learn and practice the main functions and methods of the seaborn library. You can also check out our [Seaborn tutorial for beginners](https://www.datacamp.com/tutorial/seaborn-python-tutorial) to get more familiar with the popular Python library. Creating a single seaborn line plot We can create a line plot showing the relationships between two continuous variables as follows: **Output**:  The above graph shows the EUR-USD rate dynamics. We defined the variables to plot on the *x* and *y* axes (the *x* and *y* parameters) and the dataframe (data) to take these variables from. For comparison, to create the same plot using `relplot()`, we would write the following: **Output**:  In this case, we passed in one more argument specific to the `relplot()` function: `kind='line'`. By default, this function creates a scatter plot. Customizing a single seaborn line plot We can customize the above chart in many ways to make it more readable and informative. For example, we can adjust the figure size, add title and axis labels, adjust the font size, customize the line, add and customize markers, etc. Let's see how to implement these improvements in seaborn. Adjusting the figure size Since Seaborn is built on top of matplotlib, we can use `matplotlib.pyplot` to adjust the figure size: **Output**:  Instead, with relplot(), we can use the height and aspect (the width-to-height ratio) parameters for the same purpose: **Output**:  Adding a title and axis labels To add a graph title and axis labels, we can use the `set()` function on the seaborn line plot object passing in the title, `xlabel`, and `ylabel` arguments: **Output**:  Adjusting the font size A convenient way to adjust the font size is to use the `set_theme()` function and experiment with different values of the `font_scale` parameter: **Output**:  Note that we also added `style='white'` to avoid overriding the initial style. Changing the line color, style, and size To customize the plot line, we can pass in some optional parameters in common with `matplotlib.pyplot.plot`, such as `color`, `linestyle`, or `linewidth`: **Output**:  Adding markers and customizing their color, style, and size It's possible to add markers on the line and customize their appearance. Also, in this case, we can use some parameters from matplotlib, such as `marker`, `markerfacecolor`, or `markersize`: **Output**:  The [documentation](https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.plot.html) provides us with the ultimate list of the parameters to use for improving the aesthetics of a seaborn line plot. In particular, we can see all the [possible choices of markers](https://matplotlib.org/stable/api/markers_api.html#module-matplotlib.markers). In our [Seaborn cheat sheet](https://www.datacamp.com/resources/cheat-sheets/python-seaborn-cheat-sheet), you'll find other ways to customize a line plot in Seaborn. Seaborn Line Plots With Multiple Lines Often, we need to explore how several continuous variables change depending on another continuous variable. For this purpose, we can build a seaborn line plot with multiple lines. The functions `lineplot()` and `relplot()` are also applicable to such cases. Creating a seaborn line plot with multiple lines Technically, it's possible to create a seaborn line plot with multiple lines just by building a separate axes object for each dependent variable, i.e., each line: **Output**:  Above, we extracted two more subsets from our initial dataframe `daily_exchange_rate_df` – for Australian and Canadian dollars – and plotted each euro rate against time. However, there are more efficient solutions to it: using the `hue`, `style`, or `size` parameters, available in both `lineplot()` and `relplot()`. Using the hue parameter This parameter works as follows: we assign to it the name of a dataframe column containing categorical values, and then seaborn generates a line plot for each category, giving a different color to each line: **Output**:  With just one line of simple code, we created a seaborn line plot for three categories. Note that we passed in the initial dataframe `daily_exchange_rate_df` instead of its subsets for different currencies. Using the style parameter The style parameter works in the same way as hue, only that it distinguishes between the categories by using different line styles (solid, dashed, dotted, etc.), without affecting the color: **Output**:  Using the size parameter Just like hue and style, the size parameter creates a separate line for each category. It doesn't affect the color and style of the lines but makes each of them of different width: **Output**:  Customizing a seaborn line plot with multiple lines Let's now experiment with the aesthetics of our graph. Some techniques here are identical to those we applied to a single Seaborn line plot. The others are specific only to line plots with multiple lines. Overall adjustments We can adjust the figure size, add a title and axis labels, and change the font size of the above graph in the same way as we did for a single line plot: **Output**:  Changing the color, style, and size of each line Earlier, we saw that when the hue, style, or size parameters are used, seaborn provides a default set of colors/styles/sizes for a line plot with multiple lines. If necessary, we can override these defaults and select colors/styles/sizes by ourselves. When we use the hue parameter, we can also pass in the `palette` argument as a list or tuple of matplotlib color names. I would read our tutorial, [Seaborn Color Palette: Quick Guide to Picking Colors](https://www.datacamp.com/tutorial/seaborn-palettes), to understand more about color theory and to get lots of good ideas to make your visuals look nice. **Output**:  It's also possible to apply directly an existing matplotlib palette: **Output**:  At the same time, when using `hue`, we can still adjust the line style and width of all the lines passing in the arguments `linestyle` and `linewidth`: **Output**:  Instead, when we create a seaborn line plot with multiple lines using the style parameter, we can assign a list (or a tuple) of lists (or tuples) to a parameter called dashes: **Output**:  In the above list of lists assigned to dashes, the first item of each sublist represents the length of a segment of the corresponding line, while the second item – the length of a gap. Note: to represent a solid line, we need to set the length of a gap to zero, e.g.: `[1, 0]`. To adjust the color and width of all the lines of this graph, we provide the arguments color and linewidth, just like we did when customizing a single seaborn line plot: **Output**:  Finally, when we use the size parameter to create a seaborn multiple line plot, we can regulate the width of each line through the `sizes` parameter. It takes in a list (or a tuple) of integers: **Output**:  To customize the color and style of all the lines of this plot, we need to provide the arguments linestyle and color: **Output**:  Adding markers and customizing their color, style, and size We may want to add markers on our seaborn multiple line plot. To add markers of the same color, style, and size on all the lines, we need to use the parameters from matplotlib, such as marker, `markerfacecolor`, `markersize`, etc., just as we did for a single line plot: **Output**:  Things are different, though, when we want different markers for each line. In this case, we need to use the markers parameter, which, however, according to seaborn functionalities, works only when the style parameter is specified: **Output**:  On the above plot, we can make all the lines solid by providing the dashes argument and setting the `[1, 0]` style pattern to each line: **Output**:  Conclusion To recap, in this tutorial, we learned a range of ways to create and customize a Seaborn line plot with either a single or multiple lines. As a way forward, with seaborn, we can do much more to further adjust a line plot. For example, we can: Group lines by more than one categorical variable Customize the legend Create line plots with multiple lines on different facets Display and customize the confidence interval Customize time axis ticks and their labels for a time series line plot To dig deeper into what and how can be done with seaborn, consider taking our course [Intermediate Data Visualization with Seaborn](https://www.datacamp.com/courses/intermediate-data-visualization-with-seaborn). |
| Shard | 136 (laksa) |
| Root Hash | 7979813049800185936 |
| Unparsed URL | com,datacamp!www,/tutorial/python-seaborn-line-plot-tutorial s443 |