How to plot a dashed line on a Seaborn lineplot in Matplotlib?

To plot a dashed line on a Seaborn lineplot, we can use linestyle="dashed" in the argument of lineplot(). This creates visually distinct line patterns that are useful for differentiating multiple data series.

Steps

  • Set the figure size and adjust the padding between and around the subplots.

  • Create x and y data points using numpy.

  • Use lineplot() method with x and y data points in the argument and linestyle="dashed".

  • To display the figure, use show() method.

Example

import seaborn as sns
import numpy as np
from matplotlib import pyplot as plt

plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True

x = np.random.rand(10)
y = np.random.rand(10)

ax = sns.lineplot(x=x, y=y, linestyle="dashed")
plt.show()

Different Line Styles

Seaborn supports various line styles beyond dashed lines ?

import seaborn as sns
import numpy as np
from matplotlib import pyplot as plt

plt.figure(figsize=(10, 6))

x = np.linspace(0, 10, 20)
y1 = np.sin(x)
y2 = np.cos(x)
y3 = np.sin(x + 1)

sns.lineplot(x=x, y=y1, linestyle="solid", label="Solid")
sns.lineplot(x=x, y=y2, linestyle="dashed", label="Dashed")
sns.lineplot(x=x, y=y3, linestyle="dotted", label="Dotted")

plt.legend()
plt.title("Different Line Styles in Seaborn")
plt.show()

Line Style Options

Line Style Parameter Value Description
Solid "solid" or "-" Continuous line (default)
Dashed "dashed" or "--" Broken line with dashes
Dotted "dotted" or ":" Line made of dots
Dash-dot "dashdot" or "-." Alternating dashes and dots

Conclusion

Use linestyle="dashed" in sns.lineplot() to create dashed lines. Different line styles help distinguish multiple data series in the same plot, improving visualization clarity.

Updated on: 2026-03-25T21:13:16+05:30

6K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements