Skip to main content
Practice

Customizing Lines and Markers

Now that you can create basic line plots with plt.plot(), it’s time to make them stand out by customizing their appearance.

Matplotlib lets you modify the line style, color, and marker — the symbols that highlight individual data points.

These small tweaks can make your plots clearer, more readable, and more visually appealing.


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 also combine all three features — color, line style, and marker — into one concise format.

For example: "g--o" creates a green dashed line with circle markers.

Want to learn more?

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