Matplotlib Markers

Markers let you highlight individual data points on a Matplotlib line or scatter plot.

Adding markers to a plot

By default, plt.plot() draws only a connecting line with no visible dots at each data point. Passing the marker keyword argument tells Matplotlib to draw a small symbol at every (x, y) pair, which is useful when the underlying data points themselves matter, not just the trend between them.

Example

import matplotlib.pyplot as plt

days = [1, 2, 3, 4, 5]
temps = [15, 18, 17, 21, 19]

plt.plot(days, temps, marker="o")
plt.show()

Marker reference

MarkerDescription
'o'Circle
'*'Star
'.'Point
','Pixel
'x'X
'X'Filled X
'+'Plus
'P'Filled plus
's'Square
'D'Diamond
'd'Thin diamond
'^' / 'v'Triangle up / down
'<' / '>'Triangle left / right
'p'Pentagon
'h'Hexagon

The fmt shorthand string

Marker, line style, and color can all be combined into a single short string, sometimes called the fmt (format) string, passed as the third positional argument to plt.plot(). The pattern is marker, then line style, then color, and any of the three can be left out.

Example

import matplotlib.pyplot as plt

x = [1, 2, 3, 4, 5]
y = [2, 4, 3, 6, 5]

plt.plot(x, y, "o--r")
plt.show()

Customizing marker size and color

Beyond the shape, you can control a marker's size with markersize (or the shorthand ms), the outline color with markeredgecolor (mec), and the fill color with markerfacecolor (mfc).

Example

import matplotlib.pyplot as plt

x = [1, 2, 3, 4, 5]
y = [5, 7, 6, 9, 8]

plt.plot(x, y, marker="o", ms=12, mec="black", mfc="gold")
plt.show()
Note: If you only want markers with no connecting line, set linestyle to "none" (or pass an empty string in the fmt shorthand), which effectively turns plt.plot() into a scatter-style plot.