Skip to main content
MahiDev — Learn. Build. Become AI-ready.

Lesson 06

Markers on a Line

Mark the real measurements on a line with marker, and control their shape, size, fill colour, and edge colour with ms, mfc, and mec.

Intermediate25 min
Markers on a Line hero Module 25 Lesson 6Markers on a Line hero Module 25 Lesson 6

A line is drawn between measurements, so from the line alone you cannot tell where a real reading ends and interpolation begins. A marker puts a dot on each actual value and removes the doubt. With twelve readings that is helpful; with twelve hundred it is a smudge, so markers are for sparse data.

A grid of marker codes with the shape each one drawsA grid of marker codes with the shape each one draws

Marking the measurements

marker takes a short code for the shape. Every data point gets one, so the reader can see there were seven readings rather than a smooth curve.

python
import matplotlib.pyplot as plt

days = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]
signups = [42, 58, 51, 66, 73, 61, 47]

plt.plot(days, signups, marker="o")
plt.title("Seven readings, joined")
plt.show()

print("points drawn:", len(signups))

Output:

text
points drawn: 7
A line chart with a circular marker on every measurementA line chart with a circular marker on every measurement

Size, face, and edge

Three more arguments dress the markers: ms is the marker size in points, mfc is the marker face colour, the inside, and mec is the marker edge colour, the outline. The long names markersize, markerfacecolor, and markeredgecolor do the same and read better in shared code.

python
import matplotlib.pyplot as plt

days = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]
signups = [42, 58, 51, 66, 73, 61, 47]

plt.plot(
    days,
    signups,
    color="#2563EB",
    marker="o",
    ms=11,
    mfc="#F8FAFC",
    mec="#2563EB",
)
plt.title("Hollow markers keep the line visible")
plt.show()

print("busiest day:", days[signups.index(max(signups))])

Output:

text
busiest day: Fri

A white face with a coloured edge is a good default: the marker stays visible where the line doubles back over itself.

Markers with no line

Set linestyle="None" and you keep the markers but drop the joining line. That is the right chart when the x axis is ordered but the gaps between readings are uneven, so drawing through them would be a guess.

python
import matplotlib.pyplot as plt

day_number = [1, 2, 5, 6, 12, 19, 20]
weight = [71.2, 71.0, 70.4, 70.6, 69.8, 69.1, 69.0]

plt.plot(day_number, weight, linestyle="None", marker="D", color="#EC4899")
plt.title("Weigh-ins, not a daily record")
plt.xlabel("day of the month")
plt.ylabel("kilograms")
plt.show()

print("readings:", len(day_number), "over", day_number[-1] - day_number[0], "days")

Output:

text
readings: 7 over 19 days

One marker per series

When several lines share a chart, give each one its own marker as well as its own colour. Readers who cannot separate the colours, and printers that cannot reproduce them, still get the message.

python
import matplotlib.pyplot as plt

days = ["Mon", "Tue", "Wed", "Thu", "Fri"]
north = [42, 58, 51, 66, 73]
south = [30, 35, 44, 41, 52]

plt.plot(days, north, marker="o", label="Northgate")
plt.plot(days, south, marker="s", linestyle="--", label="Southbank")
plt.legend()
plt.show()

print("shape and dash carry the same message as colour")

Output:

text
shape and dash carry the same message as colour

Key takeaways

  • marker puts a shape on every real measurement

  • ms sets the size, mfc the fill, and mec the outline

  • linestyle='None' keeps the markers and drops the line

  • A different marker per series survives greyscale printing

  • Next: Grid Lines and Fonts

  • Previous: Line Styles and Colours

Loading playground…

Check your understanding

Markers on a Line Quiz

What does a marker show?

1 / 10