How can you create a dashed line in matplotlib?
How can you create a dashed line in matplotlib?
Solution
✅ Correct Option: 1
The linestyle parameter (short form ls) of plt.plot() sets the line pattern. It accepts 'dashed' or the shorthand '--', for example plt.plot(x, y, linestyle='dashed').
Option 2: line_style is not a valid keyword, because matplotlib spells it without an underscore.
Option 3: style is not a line property of plt.plot(). The nearest match is plt.style.use(), which sets a whole plot theme.
Other linestyle values: 'solid' or '-', 'dotted' or ':', 'dashdot' or '-.'.
Related questions:
2025: 30 May Shift 2
2026: 20 May Shift 1
2026: 19 May Shift 1