How to Plot a Dashed Line on Seaborn Lineplot? Last Updated : 18 Jul, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report Seaborn is a popular data visualization library in Python that is built on top of Matplotlib. It provides a high-level interface for drawing attractive and informative statistical graphics. One common requirement in data visualization is to differentiate between various lines on a plot. This can be easily achieved by using different line styles, such as solid, dashed, or dotted lines. In this article, we will walk through the steps to plot a dashed line using Seaborn's lineplot function.Basic Lineplot with SeabornLet's begin by creating a simple line plot using Seaborn. First, import the necessary libraries and create some sample data. Python import seaborn as sns import matplotlib.pyplot as plt import pandas as pd # Sample data data = pd.DataFrame({ 'x': range(10), 'y': [i**2 for i in range(10)] }) # Basic lineplot sns.lineplot(x='x', y='y', data=data) plt.show() Output: This code will generate a basic line plot with a solid line.Customizing Line StylesSeaborn allows you to customize various aspects of the plot, including the line style. You can specify the line style using the linestyle parameter.Plotting a Dashed LineTo plot a dashed line, you can set the linestyle parameter to '--'. Here’s how you can do it: Python # Dashed lineplot sns.lineplot(x='x', y='y', data=data, linestyle='--') plt.show() Output: This will produce a line plot where the line is dashed instead of solid.Complete ExampleLet’s combine everything into a complete example. We will create a dataset with multiple lines and plot them with different line styles. Python import numpy as np # Create sample data np.random.seed(0) x = np.linspace(0, 10, 100) y1 = np.sin(x) y2 = np.cos(x) # Create a DataFrame data = pd.DataFrame({ 'x': np.concatenate([x, x]), 'y': np.concatenate([y1, y2]), 'type': ['sin']*100 + ['cos']*100 }) # Plot with different line styles sns.lineplot(x='x', y='y', hue='type', style='type', data=data, dashes=['', (2, 2)]) plt.show() In this example, we use the dashes parameter to specify different dash patterns for each line. An empty string '' represents a solid line, and (2, 2) represents a dashed line with a dash length of 2 and a space length of 2.ConclusionSeaborn provides a straightforward way to customize the appearance of your plots, including line styles. By using the linestyle or dashes parameters, you can easily create dashed lines and other custom line styles. This enhances the clarity and readability of your plots, making your data visualizations more effective. Comment More infoAdvertise with us Next Article How to Plot a Dashed Line on Seaborn Lineplot? F frostmkrcr Follow Improve Article Tags : Blogathon Data Visualization AI-ML-DS Python-Seaborn Data Science Blogathon 2024 +1 More Similar Reads Machine Learning Tutorial Machine learning is a branch of Artificial Intelligence that focuses on developing models and algorithms that let computers learn from data without being explicitly programmed for every task. In simple words, ML teaches the systems to think and understand like humans by learning from the data.Machin 5 min read Non-linear Components In electrical circuits, Non-linear Components are electronic devices that need an external power source to operate actively. Non-Linear Components are those that are changed with respect to the voltage and current. Elements that do not follow ohm's law are called Non-linear Components. Non-linear Co 11 min read Linear Regression in Machine learning Linear regression is a type of supervised machine-learning algorithm that learns from the labelled datasets and maps the data points with most optimized linear functions which can be used for prediction on new datasets. It assumes that there is a linear relationship between the input and output, mea 15+ min read Spring Boot Tutorial Spring Boot is a Java framework that makes it easier to create and run Java applications. It simplifies the configuration and setup process, allowing developers to focus more on writing code for their applications. This Spring Boot Tutorial is a comprehensive guide that covers both basic and advance 10 min read Support Vector Machine (SVM) Algorithm Support Vector Machine (SVM) is a supervised machine learning algorithm used for classification and regression tasks. It tries to find the best boundary known as hyperplane that separates different classes in the data. It is useful when you want to do binary classification like spam vs. not spam or 9 min read Logistic Regression in Machine Learning Logistic Regression is a supervised machine learning algorithm used for classification problems. Unlike linear regression which predicts continuous values it predicts the probability that an input belongs to a specific class. It is used for binary classification where the output can be one of two po 11 min read Class Diagram | Unified Modeling Language (UML) A UML class diagram is a visual tool that represents the structure of a system by showing its classes, attributes, methods, and the relationships between them. It helps everyone involved in a projectâlike developers and designersâunderstand how the system is organized and how its components interact 12 min read 100+ Machine Learning Projects with Source Code [2025] This article provides over 100 Machine Learning projects and ideas to provide hands-on experience for both beginners and professionals. Whether you're a student enhancing your resume or a professional advancing your career these projects offer practical insights into the world of Machine Learning an 5 min read K means Clustering â Introduction K-Means Clustering is an Unsupervised Machine Learning algorithm which groups unlabeled dataset into different clusters. It is used to organize data into groups based on their similarity. Understanding K-means ClusteringFor example online store uses K-Means to group customers based on purchase frequ 4 min read K-Nearest Neighbor(KNN) Algorithm K-Nearest Neighbors (KNN) is a supervised machine learning algorithm generally used for classification but can also be used for regression tasks. It works by finding the "k" closest data points (neighbors) to a given input and makesa predictions based on the majority class (for classification) or th 8 min read Like