We can use matplotlib.rcParams[‘lines.linestyle’] to set the style of line in matplotlib. Here is the tutorial:
Understand Matplotlib.rcParams: A Beginner Guide – Matplotlib Tutorial
In this tutorial, we will list all the line styles to help matplotlib beginners to use.
A Full List of Line Style
The style of a line in matplotlib can be:
['-', '--', '-.', ':', 'solid', 'dashed', 'dashdot', 'dotted', 'none', ' ', '']
We will draw a sine function with each line style.
# draw sine function l = ['-', '--', '-.', ':', 'solid', 'dashed', 'dashdot', 'dotted', 'none', ' ', ''] for i in l: mpl.rcParams['lines.linestyle'] = i plt.title('sin function with ' + i) plt.plot(x, y, label='$sin(x)$') plt.show()
Run this code, you will get an image like this: