Dash patterns of lines are designated by the linestyle or ls parameter. It can sometimes be used as a positional argument for convenience. For example, in line plots, we can specify the following:
- 'solid' or '-': Solid line; default
- 'dashed' or '--': Equally spaced dashes
- 'dashdot' or '-.': Alternate dashes and dots
- '.': Loose dotted line
- ':': Packed dotted line
- 'None', ' ', '': No visible line
- (offset, on-off-dash-seq): Customized dashes
The following is an example of lines in different dash patterns:
import matplotlib.pyplot as plt
# Prepare 4 data series of sine curves
y = [np.sin(i) for i in np.arange(0.0, 10.0, 0.1)]
dash_capstyles = ['-','--','-.','.',':']
# Plot each data series in different cap dash styles
for i,x in enumerate(dash_capstyles):
plt.plot([n*(i+1) for n in y],x,label=x)
plt.legend(fontsize=16,loc='lower left')
plt.show()
We can see the effect of each dash style in the following figure: