Linestyles in Matplotlib Python Last Updated : 25 Apr, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report In Matplotlib we can change appearance of lines in our plots by adjusting their style and can choose between solid, dashed, dotted or dash-dot lines to make our plots easier to understand. By default it uses a solid line while plotting data but we can change the line style using linestyle or ls argument in plot() method.Syntax: plt.plot(x, y, linestyle='line_style', color='color')where line_style is:CharacterDefinition–Solid line—Dashed line-.dash-dot line: Dotted line.Point markerAnd colors can be:CodesDescriptionbblueggreenrredccyanmmagentayyellowkblackwwhiteExample 1: Dotted Line Style in Bluex = [0, 1, 2, 3, 4]: Define x-values for the plot.y = [0, 1, 4, 9, 16]: Define y-values for the plot.plt.plot(x, y, linestyle=':', color='b', label='Dotted Line'): Plot the data with a dotted blue line and label it Dotted Line. Python import matplotlib.pyplot as plt x = [0, 1, 2, 3, 4] y = [0, 1, 4, 9, 16] plt.plot(x, y, linestyle=':', color='b', label='Dotted Line') plt.xlabel('X-axis') plt.ylabel('Y-axis') plt.title('Dotted Line Style') plt.legend() plt.show() Output:Dotted lineExample 2: Dash-dot Line Style in Yellowplt.plot(x, y, linestyle='-.', color='y', label='Dash-dot Line'): Plot the x and y values with a dash-dot yellow line and label it as Dash-dot Line. Python import matplotlib.pyplot as plt x = [0, 2, 4, 6, 8, 10, 12, 14] y = [4, 2, 8, 6, 10, 5, 12, 6] plt.plot(x, y, linestyle='-.', color='y', label='Dash-dot Line') plt.xlabel('X-axis') plt.ylabel('Y-axis') plt.title('Dash-dot Line Style') plt.legend() plt.show() Output:Dash-dot lineExample 3: Dashed Line Style in Greenplt.plot(x, y, linestyle='--', color='g', label='Dashed Line'): Plot the x and y values with a green dashed line and label it as Dashed Line. Python import matplotlib.pyplot as plt x = [0, 1, 12, 3, 4] y = [0, 1, 14, 9, 20] plt.plot(x, y, linestyle='--', color='g', label='Dashed Line') plt.xlabel('X-axis') plt.ylabel('Y-axis') plt.title('Dashed Line Style') plt.legend() plt.show() Output:Dashed lineExample 4: Solid Line Style in Redplt.plot(x, y, linestyle='-', color='r', label='Solid Line'): Plot the x and y values with a solid red line and label it as Solid Line. Python import matplotlib.pyplot as plt x = [0, 10, 2, 13, 14] y = [0, 11, 14, 19, 16] plt.plot(x, y, linestyle='-', color='r', label='Solid Line') plt.xlabel('X-axis') plt.ylabel('Y-axis') plt.title('Solid Line Style') plt.legend() plt.show() Output:Solid lineWith these simple line style customizations we can make our Matplotlib plots interactive and easier to interpret. By exploring different line styles we can focus on trends, distinguish data series and improve overall readability of our visualizations. Comment More infoAdvertise with us Next Article Matplotlib.pyplot.ion() in Python P patildhanu4111999 Follow Improve Article Tags : Python Python-matplotlib Practice Tags : python Similar Reads Line chart in Matplotlib - Python Matplotlib is a data visualization library in Python. The pyplot, a sublibrary of Matplotlib, is a collection of functions that helps in creating a variety of charts. Line charts are used to represent the relation between two data X and Y on a different axis. In this article, we will learn about lin 6 min read Matplotlib.pyplot.ion() in Python Matplotlib is an amazing visualization library in Python for 2D plots of arrays. Matplotlib is a multi-platform data visualization library built on NumPy arrays and designed to work with the broader SciPy stack. The matplotlib.pyplot.ion() is used to turn on interactive mode. To check the status of 4 min read Matplotlib.axes.Axes.get_lines() in Python Matplotlib is a library in Python and it is numerical â mathematical extension for NumPy library. The Axes Class contains most of the figure elements: Axis, Tick, Line2D, Text, Polygon, etc., and sets the coordinate system. And the instances of Axes supports callbacks through a callbacks attribute. 2 min read Matplotlib.pyplot.hlines() in Python Matplotlib is an amazing visualization library in Python for 2D plots of arrays. Matplotlib is a multi-platform data visualization library built on NumPy arrays and designed to work with the broader SciPy stack. Matplotlib.pyplot.hlines() The Matplotlib.pyplot.hlines() is used to draw horizontal lin 2 min read Matplotlib.axes.Axes.hlines() in Python Matplotlib is a library in Python and it is numerical - mathematical extension for NumPy library. The Axes Class contains most of the figure elements: Axis, Tick, Line2D, Text, Polygon, etc., and sets the coordinate system. And the instances of Axes supports callbacks through a callbacks attribute. 2 min read Matplotlib.axes.Axes.add_line() in Python Matplotlib is a library in Python and it is numerical - mathematical extension for NumPy library. The Axes Class contains most of the figure elements: Axis, Tick, Line2D, Text, Polygon, etc., and sets the coordinate system. And the instances of Axes supports callbacks through a callbacks attribute. 2 min read Like