Line chart in seaborn with lineplot


In this tutorial we are going to use the following data for illustration purposes.

import numpy as np

# Seed
rng = np.random.RandomState(0)

# Data simulation
x = np.array(range(0, 20))
y = np.square(x) + rng.uniform(0, 100, 20)

# Data set
df = {'x': x, 'y': y}

Basic line charts with lineplot

The lineplot function from seaborn allows creating line graphs in Python. You just need to pass your data to the function to create a basic plot with a blue solid line by default.

import seaborn as sns

sns.lineplot(x, y)

# Equivalent to:
sns.lineplot(x = "x", y = "y", data = df)

Basic line chart in seaborn

Line plot with markers

In case you want to add markers to the visualization you can set the desired marker with marker, as shown below.

import seaborn as sns

sns.lineplot(x = "x", y = "y", data = df,
             marker = "o")

Line plot with markes in Python seaborn

Line colors and styles

Change the color of the line with the lineplot function in seaborn


The color argument of the function controls the color of the line of the plot. You can select the color you desire for your visualization.

import seaborn as sns

sns.lineplot(x = "x", y = "y", data = df,
             color = "red")

Seaborn lineplot function dashed line

Dashed line

The style of the line can be set with the linestyle argument. In the following example we are creating a dashed line but you could also create a dotted line with "dotted".

import seaborn as sns

sns.lineplot(x = "x", y = "y", data = df,
            linestyle = "dashed")

Line width in seaborn lineplot

Width of the line

Finally, if you want to modify the default width of the line you can pass any value to linewidth, as in the example below.

import seaborn as sns

sns.lineplot(x = "x", y = "y", data = df,
             linewidth = 3)
Storytelling with Data

A Data Visualization Guide for Business Professionals

Buy on Amazon
Fundamentals of Data Visualization

A Primer on Making Informative and Compelling Figures

Buy on Amazon

See also