How to plot a dashed line in matplotlib? Last Updated : 12 Jun, 2025 Comments Improve Suggest changes Like Article Like Report Matplotlib is used to create visualizations and plotting dashed lines is used to enhance the style and readability of graphs. A dashed line can represent trends, relationships or boundaries in data. Below we will explore how to plot and customize dashed lines using Matplotlib. To plot dashed line:Syntax: matplotlib.pyplot.plot(x, y, linestyle='dashed')where:x: X-axis points on the line.y: Y-axis points on the line.linestyle: Change the style of the line.1. Plotting a Basic Dashed LineThe simplest way to plot a dashed line in Matplotlib is by setting the linestyle parameter to 'dashed' or using the shorthand '--' Python import matplotlib.pyplot as plt x = [1.5, 2.6, 3.5, 4, 9] y = [3.25, 6.3, 4.23, 1.35, 3] plt.plot(x, y, linestyle='dashed') # or linestyle='--' plt.xlabel("X-axis") plt.ylabel("Y-axis") plt.show() Output Dashed line plot2. Customizing the Color of the Dashed LineYou can easily change the color of your dashed line to match your design or to make different lines distinguishable. Python import matplotlib.pyplot as plt x = [1.5, 2.6, 3.5, 4, 9] y = [3.25, 6.3, 4.23, 1.35, 3] plt.plot(x, y, linestyle='--', color='gold') plt.xlabel("X-axis") plt.ylabel("Y-axis") plt.show() Output Golden dashed line3. Adjusting the Width (Thickness) of the Dashed LineTo make the dashed line thicker or thinner, use the linewidth or lw parameter. Python import matplotlib.pyplot as plt x = [1.5, 5.6, 3.5, 4, 9] y1 = [1, 4, 3, 4, 5] y2 = [6, 7, 4, 9, 10] plt.plot(x, y1, linestyle='--', color='black', linewidth=1) # thinner line plt.plot(x, y2, linestyle='--', color='red', linewidth=4) # thicker line plt.show() OutputThin & thick dashes4. Creating Custom Dash PatternsIn addition to predefined styles, Matplotlib lets you create custom dash patterns using set_dashes() which takes a list of dash and gap lengths (in points) for greater control over line appearance. Python import matplotlib.pyplot as plt x = [1.5, 2.6, 3.5, 4, 9] y = [3.25, 6.3, 4.23, 1.35, 3] line, = plt.plot(x, y, color='blue') line.set_dashes([5, 10, 15, 5]) plt.show() Output Patterned dashed lineWith these customizations we can easily plot dashed lines in our graphs. Comment More infoAdvertise with us Next Article How to plot a dashed line in matplotlib? S skrg141 Follow Improve Article Tags : Python Python-matplotlib Practice Tags : python Similar Reads How to Add an Average Line to Plot in Matplotlib In this article, we will learn how we can add an average line to a plot in matplotlib. We will discuss the steps to add a horizontal average line using the axhline function, as well as the steps to add a vertical average line using the axvline function in Matplotlib. Throughout the article, we will 5 min read How to Plot a Dashed Line on Seaborn Lineplot? 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 2 min read Plot a Horizontal line in Matplotlib In Matplotlib, we can draw horizontal lines on a plot to indicate thresholds, reference points or important levels in the data. These lines can be used to highlight specific values for better visualization. We can create a single horizontal line, which is useful for marking a single reference level, 3 min read Plot a Vertical line in Matplotlib Plotting vertical lines is a technique in data visualization which is used to highlight specific data points, thresholds or regions on a graph. Whether we're marking key values, dividing data into segment, vertical lines can make our charts more informative. In this article, we'll see different meth 3 min read How to update a plot in Matplotlib? In this article, let's discuss how to update a plot in Matplotlib. Updating a plot simply means plotting the data, then clearing the existing plot, and then again plotting the updated data and all these steps are performed in a loop. Functions Used:canvas.draw(): It is used to update a figure that 1 min read Like