Markers, Line Styles & Colors

Matplotlib is a Python library for creating charts and visualizations — and this lesson is about styling them, so each line looks exactly the way you want.

Learn Markers, Line Styles & Colors in our free Matplotlib course — a beginner-friendly interactive lesson with worked examples, a practice exercise and a…

Part of the free Matplotlib course at LearnCodingFast — hands-on lessons with examples you run in your browser, plus practice exercises and a quick quiz.

You'll set colors, switch between solid, dashed, and dotted lines, add point markers, and learn the compact format-string shortcut like 'ro--' .

Three keyword arguments give you full control of a line's appearance: color , linestyle , and linewidth .

What you'll see: a single line that is clearly green, drawn as a series of dashes rather than a solid stroke, and noticeably thicker than the default.

Markers draw a shape at each data point, which is useful when you want to highlight the exact values, not just the trend. Use marker= and size them with markersize= .

What you'll see: a blue line with a bold filled circle sitting on every data point, making each of the five measured values easy to spot.

Matplotlib accepts a compact third argument that bundles color, marker, and line style into one string. 'ro--' means red circles joined by a dashed line. The order is color, then marker, then style.

What you'll see: a red dashed line with circle markers and a green solid line with triangle markers, both fully styled from a single short string each.

Replace each ___ to style this line your way.

❌ ValueError: Unrecognized character / invalid format string

Your format string uses letters Matplotlib doesn't know. Stick to valid color, marker, and style codes like 'ro--' .

You set linestyle but no marker . Add marker="o" to show points.

Plot two lines with contrasting colors, styles, and markers.

Lesson 5 complete — you control the look!

You set colors, line styles, widths, and markers, and learned the compact format-string shortcut.

🚀 Up next: Saving Figures — export your polished charts to PNG, SVG, and PDF files.

Practice quiz

Which argument sets a line's color?

  • tint=
  • color=
  • shade=
  • hue=

Answer: color=. Pass color= a name, single-letter code, or hex string.

Which linestyle value gives a dashed line?

  • '--'
  • ':'
  • '-'
  • '-.'

Answer: '--'. linestyle='--' is dashed; ':' is dotted, '-' solid, '-.' dash-dot.

Which hex string is a valid color?

  • '1f77b4'
  • '#1f77b4'
  • '0x1f77b4'
  • 'rgb(31,119,180)'

Answer: '#1f77b4'. Matplotlib hex colors start with #, like '#1f77b4'.

What does the format string 'ro--' mean?

  • Red dotted line, no markers
  • Orange squares, solid line
  • Round line, orange dashes
  • Red circle markers, dashed line

Answer: Red circle markers, dashed line. 'ro--' is color red, circle markers, dashed line — color, marker, then style.

Which argument adds point markers?

  • marker=
  • point=
  • dot=
  • symbol=

Answer: marker=. marker='o' draws circles; 's', '^', '*' are other shapes.

Which argument controls line thickness?

  • thickness=
  • weight=
  • linewidth=
  • bold=

Answer: linewidth=. linewidth= sets the line thickness in points.

Which marker value draws squares?

  • '^'
  • 's'
  • '*'
  • 'o'

Answer: 's'. marker='s' draws squares; '^' is a triangle, '*' a star, 'o' a circle.

What is the order of parts in a format string like 'g^-'?

  • color, marker, line style
  • marker, color, line style
  • line style, color, marker
  • color, line style, marker

Answer: color, marker, line style. The order is color, then marker, then line style.

Why might markers not appear?

  • linewidth is too high
  • color was a hex string
  • No marker= was set
  • linestyle was solid

Answer: No marker= was set. Without a marker= argument no point markers are drawn.

Which linestyle value is dotted?

  • '--'
  • '-.'
  • '-'
  • ':'

Answer: ':'. linestyle=':' draws a dotted line.