Skip to main contentSkip to solution

Which of the following properties of matplotlib is used to change the type of lines, such as "solid", "dotted", "dashed" etc.?

Solution

✅ Correct Option: 2

The linestyle property (short form ls) sets the pattern of a line in matplotlib, such as "solid", "dotted", "dashed" or "dashdot". Example: plt.plot(x, y, linestyle="dashed").

Shorthand symbols also work: "-" solid, "--" dashed, ":" dotted, "-." dash-dot.


Option 1: linewidth (or lw) changes the thickness of the line, not its pattern.

Option 3: linetype is not a matplotlib property. It is a common mix-up with linestyle.

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question