Skip to main content
Practice

Customizing Lines and Markers


Now that you know how to use plt.plot() to draw basic lines, let’s make those plots more expressive by customizing their appearance.

Matplotlib allows you to style the line, the color, and the marker — the symbol used to highlight each data point.

These customizations help differentiate multiple lines and improve the clarity of your visualizations.


Line Styles

Use the linestyle argument to change the look of the line:

  • '-' → solid (default)
  • '--' → dashed
  • ':' → dotted
  • '-.' → dash-dot

Colors

Change the color using the color argument:

  • Named colors: "red", "blue", "green"
  • Single-letter codes: 'r', 'b', 'g'
  • Hex codes: "#FF5733" for custom shades

Markers

To mark each data point on the line, use the marker argument:

  • 'o' → circle
  • 's' → square
  • '^' → triangle
  • 'x' → x-mark

You can even combine all three features into one concise string:
For example, "g--o" means: green dashed line with circle markers.


What’s Next?

Now that your plots can be styled and highlighted clearly, the next step is to add labels and legends so viewers understand what each part of your chart represents.

Want to learn more?

Join CodeFriends Plus membership or enroll in a course to start your journey.