🕷️ Crawler Inspector

URL Lookup

Direct Parameter Lookup

Raw Queries and Responses

1. Shard Calculation

Query:
Response:
Calculated Shard: 136 (from laksa131)

2. Crawled Status Check

Query:
Response:

3. Robots.txt Check

Query:
Response:

4. Spam/Ban Check

Query:
Response:

5. Seen Status Check

ℹ️ Skipped - page is already crawled

📄
INDEXABLE
CRAWLED
6 hours ago
🤖
ROBOTS ALLOWED

Page Info Filters

FilterStatusConditionDetails
HTTP statusPASSdownload_http_code = 200HTTP 200
Age cutoffPASSdownload_stamp > now() - 6 MONTH0 months ago
History dropPASSisNull(history_drop_reason)No drop reason
Spam/banPASSfh_dont_index != 1 AND ml_spam_score = 0ml_spam_score=0
CanonicalPASSmeta_canonical IS NULL OR = '' OR = src_unparsedNot set

Page Details

PropertyValue
URLhttps://www.datacamp.com/tutorial/python-seaborn-line-plot-tutorial
Last Crawled2026-04-07 04:31:52 (6 hours ago)
First Indexed2023-03-16 13:17:40 (3 years ago)
HTTP Status Code200
Meta TitlePython Seaborn Line Plot Tutorial: Create Data Visualizations | DataCamp
Meta DescriptionDiscover how to use Seaborn, a popular Python data visualization library, to create and customize line plots in Python.
Meta Canonicalnull
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
[![Promo \| 50% Off](https://media.datacamp.com/cms/eng-8f1435.png) 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**: ![Seaborn single-line plot with lineplot](https://images.datacamp.com/image/upload/v1678970404/Seaborn_single_line_plot_with_lineplot_76443dbb94.png) 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**: ![Seaborn single-line plot with relplot](https://images.datacamp.com/image/upload/v1678970405/Seaborn_single_line_plot_with_relplot_8c5aa62be1.png) 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**: ![Seaborn single-line plot — adjusted figure size with relplot](https://images.datacamp.com/image/upload/v1678970405/Seaborn_single_line_plot_adjusted_figure_size_with_relplot_30ea81ceb5.png) 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**: ![Seaborn line plot](https://images.datacamp.com/image/upload/v1678970913/Seaborn_plot_c4336eeb6d.png) #### 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**: ![Seaborn single-line plot — added title and axis labels](https://images.datacamp.com/image/upload/v1678970405/Seaborn_single_line_plot_added_title_and_axis_labels_5c1a3d50c5.png) #### 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**: ![Seaborn single-line plot — adjusted font size](https://images.datacamp.com/image/upload/v1678970405/Seaborn_single_line_plot_adjusted_font_size_be556826a6.png) 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**: ![Seaborn single-line plot — customized line](https://images.datacamp.com/image/upload/v1678970405/Seaborn_single_line_plot_customized_line_2e2c107afa.png) #### 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**: ![Seaborn single-line plot — added and customized markers](https://images.datacamp.com/image/upload/v1678970405/Seaborn_single_line_plot_added_and_customized_markers_0acaa7b8ac.png) 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**: ![Seaborn multiple-line plot — separate axes objects for dependent variables](https://images.datacamp.com/image/upload/v1678970405/Seaborn_multiple_line_plot_separate_axes_objects_for_dependent_variables_e1a191a6a6.png) 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**: ![Seaborn multiple-line plot using hue](https://images.datacamp.com/image/upload/v1678970405/Seaborn_multiple_line_plot_using_hue_eb6f0b71ee.png) 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**: ![Seaborn multiple-line plot using style](https://images.datacamp.com/image/upload/v1678970405/Seaborn_multiple_line_plot_using_style_91166eba94.png) #### 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**: ![Seaborn multiple-line plot using size](https://images.datacamp.com/image/upload/v1678970405/Seaborn_multiple_line_plot_using_size_861394e6e8.png) ### 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**: ![Seaborn multiple-line plot — overall adjustments](https://images.datacamp.com/image/upload/v1678970405/Seaborn_multiple_line_plot_overall_adjustments_f95963d26e.png) #### 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**: ![Seaborn multiple-line plot using hue and providing a custom palette](https://images.datacamp.com/image/upload/v1678970406/Seaborn_multiple_line_plot_using_hue_and_providing_a_custom_palette_0b9cce3f0a.png) It's also possible to apply directly an existing matplotlib palette: ``` Powered By ``` **Output**: ![Seaborn multiple-line plot using hue and providing a standard palette](https://images.datacamp.com/image/upload/v1678970406/Seaborn_multiple_line_plot_using_hue_and_providing_a_standard_palette_ea832ab974.png) 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**: ![Seaborn multiple-line plot using hue — adjusted line style, color, and width](https://images.datacamp.com/image/upload/v1678970405/Seaborn_multiple_line_plot_using_hue_adjusted_line_style_color_and_width_7acc7b08d2.png) 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**: ![Seaborn multiple-line plot using style and providing a custom pattern](https://images.datacamp.com/image/upload/v1678970405/Seaborn_multiple_line_plot_using_style_and_providing_a_custom_pattern_886647af86.png) 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**: ![Seaborn multiple-line plot using style — adjusted line style, color, and width](https://images.datacamp.com/image/upload/v1678970406/Seaborn_multiple_line_plot_using_style_adjusted_line_style_color_and_width_60f5ecf536.png) 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**: ![Seaborn multiple-line plot using size and providing custom line widths](https://images.datacamp.com/image/upload/v1678970405/Seaborn_multiple_line_plot_using_size_and_providing_custom_line_widths_ca289eef29.png) 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**: ![Seaborn multiple-line plot using size — adjusted line style, color, and width](https://images.datacamp.com/image/upload/v1678970406/Seaborn_multiple_line_plot_using_size_adjusted_line_style_color_and_width_89ef66f0a0.png) #### 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**: ![Seaborn multiple-line plot with markers of the same color, style, and size](https://images.datacamp.com/image/upload/v1678970405/Seaborn_multiple_line_plot_with_markers_of_the_same_color_style_and_size_2352b57a72.png) 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**: ![Seaborn multiple-line plot with markers of different styles](https://images.datacamp.com/image/upload/v1678970405/Seaborn_multiple_line_plot_with_markers_of_different_styles_fa0a6b77fc.png) 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**: ![Seaborn multiple-line plot with solid lines and markers of different styles](https://images.datacamp.com/image/upload/v1678970405/Seaborn_multiple_line_plot_with_solid_lines_and_markers_of_different_styles_4ec240afba.png) ## 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) ![](https://media.datacamp.com/legacy/v1649269954/Python_Seaborn_Cheat_Sheet_q074wv_6e1b5bb6c2.webp?w=256) [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) ![](https://media.datacamp.com/legacy/v1683650226/datarhys_An_absurdist_oil_painting_of_Two_snakes_wearing_glasse_3cad22b8_08dc_4dd5_a795_fb95f2bb2ab4_6564e54582.png?w=256) [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) ![](https://media.datacamp.com/legacy/v1707139067/datarhys_an_absurdist_oil_painting_of_a_coder_sat_on_the_deck_o_328fe9bb_829f_4390_9054_a1453e0d079b_97556f6623.png?w=256) [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 ![](https://media.datacamp.com/legacy/v1649269954/Python_Seaborn_Cheat_Sheet_q074wv_6e1b5bb6c2.webp?w=750) [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 ![](https://media.datacamp.com/legacy/v1683650226/datarhys_An_absurdist_oil_painting_of_Two_snakes_wearing_glasse_3cad22b8_08dc_4dd5_a795_fb95f2bb2ab4_6564e54582.png?w=750) [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. [![Joleen Bothma's photo](https://media.datacamp.com/legacy/v1658157526/Joleen_b6bf59ddd5.png?w=48)](https://www.datacamp.com/portfolio/joleen-bothma) Joleen Bothma ![](https://media.datacamp.com/legacy/v1707139067/datarhys_an_absurdist_oil_painting_of_a_coder_sat_on_the_deck_o_328fe9bb_829f_4390_9054_a1453e0d079b_97556f6623.png?w=750) [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. [![Elena Kosourova's photo](https://media.datacamp.com/legacy/v1662144772/Elena_Kosourova_598bda3f66.png?w=48)](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**: ![Seaborn single-line plot with lineplot](https://images.datacamp.com/image/upload/v1678970404/Seaborn_single_line_plot_with_lineplot_76443dbb94.png) 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**: ![Seaborn single-line plot with relplot](https://images.datacamp.com/image/upload/v1678970405/Seaborn_single_line_plot_with_relplot_8c5aa62be1.png) 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**: ![Seaborn single-line plot — adjusted figure size with relplot](https://images.datacamp.com/image/upload/v1678970405/Seaborn_single_line_plot_adjusted_figure_size_with_relplot_30ea81ceb5.png) Instead, with relplot(), we can use the height and aspect (the width-to-height ratio) parameters for the same purpose: **Output**: ![Seaborn line plot](https://images.datacamp.com/image/upload/v1678970913/Seaborn_plot_c4336eeb6d.png) 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**: ![Seaborn single-line plot — added title and axis labels](https://images.datacamp.com/image/upload/v1678970405/Seaborn_single_line_plot_added_title_and_axis_labels_5c1a3d50c5.png) 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**: ![Seaborn single-line plot — adjusted font size](https://images.datacamp.com/image/upload/v1678970405/Seaborn_single_line_plot_adjusted_font_size_be556826a6.png) 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**: ![Seaborn single-line plot — customized line](https://images.datacamp.com/image/upload/v1678970405/Seaborn_single_line_plot_customized_line_2e2c107afa.png) 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**: ![Seaborn single-line plot — added and customized markers](https://images.datacamp.com/image/upload/v1678970405/Seaborn_single_line_plot_added_and_customized_markers_0acaa7b8ac.png) 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**: ![Seaborn multiple-line plot — separate axes objects for dependent variables](https://images.datacamp.com/image/upload/v1678970405/Seaborn_multiple_line_plot_separate_axes_objects_for_dependent_variables_e1a191a6a6.png) 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**: ![Seaborn multiple-line plot using hue](https://images.datacamp.com/image/upload/v1678970405/Seaborn_multiple_line_plot_using_hue_eb6f0b71ee.png) 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**: ![Seaborn multiple-line plot using style](https://images.datacamp.com/image/upload/v1678970405/Seaborn_multiple_line_plot_using_style_91166eba94.png) 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**: ![Seaborn multiple-line plot using size](https://images.datacamp.com/image/upload/v1678970405/Seaborn_multiple_line_plot_using_size_861394e6e8.png) 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**: ![Seaborn multiple-line plot — overall adjustments](https://images.datacamp.com/image/upload/v1678970405/Seaborn_multiple_line_plot_overall_adjustments_f95963d26e.png) 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**: ![Seaborn multiple-line plot using hue and providing a custom palette](https://images.datacamp.com/image/upload/v1678970406/Seaborn_multiple_line_plot_using_hue_and_providing_a_custom_palette_0b9cce3f0a.png) It's also possible to apply directly an existing matplotlib palette: **Output**: ![Seaborn multiple-line plot using hue and providing a standard palette](https://images.datacamp.com/image/upload/v1678970406/Seaborn_multiple_line_plot_using_hue_and_providing_a_standard_palette_ea832ab974.png) 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**: ![Seaborn multiple-line plot using hue — adjusted line style, color, and width](https://images.datacamp.com/image/upload/v1678970405/Seaborn_multiple_line_plot_using_hue_adjusted_line_style_color_and_width_7acc7b08d2.png) 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**: ![Seaborn multiple-line plot using style and providing a custom pattern](https://images.datacamp.com/image/upload/v1678970405/Seaborn_multiple_line_plot_using_style_and_providing_a_custom_pattern_886647af86.png) 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**: ![Seaborn multiple-line plot using style — adjusted line style, color, and width](https://images.datacamp.com/image/upload/v1678970406/Seaborn_multiple_line_plot_using_style_adjusted_line_style_color_and_width_60f5ecf536.png) 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**: ![Seaborn multiple-line plot using size and providing custom line widths](https://images.datacamp.com/image/upload/v1678970405/Seaborn_multiple_line_plot_using_size_and_providing_custom_line_widths_ca289eef29.png) To customize the color and style of all the lines of this plot, we need to provide the arguments linestyle and color: **Output**: ![Seaborn multiple-line plot using size — adjusted line style, color, and width](https://images.datacamp.com/image/upload/v1678970406/Seaborn_multiple_line_plot_using_size_adjusted_line_style_color_and_width_89ef66f0a0.png) 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**: ![Seaborn multiple-line plot with markers of the same color, style, and size](https://images.datacamp.com/image/upload/v1678970405/Seaborn_multiple_line_plot_with_markers_of_the_same_color_style_and_size_2352b57a72.png) 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**: ![Seaborn multiple-line plot with markers of different styles](https://images.datacamp.com/image/upload/v1678970405/Seaborn_multiple_line_plot_with_markers_of_different_styles_fa0a6b77fc.png) 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**: ![Seaborn multiple-line plot with solid lines and markers of different styles](https://images.datacamp.com/image/upload/v1678970405/Seaborn_multiple_line_plot_with_solid_lines_and_markers_of_different_styles_4ec240afba.png) 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).
Shard136 (laksa)
Root Hash7979813049800185936
Unparsed URLcom,datacamp!www,/tutorial/python-seaborn-line-plot-tutorial s443