Matplotlib plot markers
During plotting, if we want to customize some different markers for the coordinates, we can use the plot() marker parameter of the method to define them.
The following example defines a solid circle marker:
Example
import
matplotlib.
pyplot
as
plt
import
numpy
as
np
ypoints
=
np.
array
(
[
1
,
3
,
4
,
5
,
8
,
9
,
6
,
1
,
3
,
4
,
5
,
2
,
4
]
)
plt.
plot
(
ypoints
,
marker
=
'o'
)
plt.
show
(
)
The display result is as follows:

The symbols that marker can define are as follows:
| Markup | sign before positive numbers | Description |
|---|---|---|
| "." | ![]() |
Point |
| "," | ![]() |
Pixel point |
| "o" | ![]() |
Solid circle |
| "v" | ![]() |
Triangle down |
| "^" | ![]() |
Triangle up |
| "<" | ![]() |
Triangle left |
| ">" | ![]() |
Triangle right |
| "1" | ![]() |
Tri-down |
| "2" | ![]() |
Tri-up |
| "3" | ![]() |
Tri-left |
| "4" | ![]() |
Tri-right |
| "8" | ![]() |
Octagon |
| "s" | ![]() |
Square |
| "p" | ![]() |
Pentagon |
| "P" | ![]() |
Plus (filled) |
| "*" | ![]() |
Asterisk |
| "h" | ![]() |
Hexagon 1 |
| "H" | ![]() |
Hexagon 2 |
| "+" | ![]() |
Plus sign |
| "x" | ![]() |
Multiplication x |
| "X" | ![]() |
Multiplication x (filled) |
| "D" | ![]() |
Diamond |
| "d" | ![]() |
Thin diamond |
| "|" | ![]() |
Vertical line |
| "_" | ![]() |
Horizontal line |
| 0 (TICKLEFT) | ![]() |
Left horizontal line |
| 1 (TICKRIGHT) | ![]() |
Right horizontal line |
| 2 (TICKUP) | ![]() |
Up vertical line |
| 3 (TICKDOWN) | ![]() |
Down vertical line |
| 4 (CARETLEFT) | ![]() |
Left arrow |
| 5 (CARETRIGHT) | ![]() |
Right arrow |
| 6 (CARETUP) | ![]() |
Up arrow |
| 7 (CARETDOWN) | ![]() |
Arrow down |
| 8 (CARETLEFTBASE) | ![]() |
Arrow left (centered on the midpoint) |
| 9 (CARETRIGHTBASE) | ![]() |
Arrow right (centered on the midpoint) |
| 10 (CARETUPBASE) | ![]() |
Arrow up (centered on the midpoint) |
| 11 (CARETDOWNBASE) | ![]() |
Arrow down (centered on the midpoint) |
| "None", " " or "" | No marker | |
| '$...$' | ![]() |
Render the specified character. For example, "$f$" uses the letter f as the marker. |
The following example defines the * marker:
Example
import
matplotlib.
pyplot
as
plt
import
numpy
as
np
ypoints
=
np.
array
(
[
1
,
3
,
4
,
5
,
8
,
9
,
6
,
1
,
3
,
4
,
5
,
2
,
4
]
)
plt.
plot
(
ypoints
,
marker
=
'*'
)
plt.
show
(
)
The display result is as follows:

The following example defines a down arrow:
Example
import
matplotlib.
pyplot
as
plt
import
matplotlib.
markers
plt.
plot
(
[
1
,
2
,
3
]
,
marker
=
matplotlib.
markers
.
CARETDOWNBASE
)
plt.
show
(
)
The display result is as follows:

fmt parameter
The fmt parameter defines the basic format, such as markers, line styles, and colors.
fmt = '[marker][line][color]'
For example, o:r: o represents a solid circle marker, : represents a dotted line, and r represents the color red.
Example
import
matplotlib.
pyplot
as
plt
import
numpy
as
np
ypoints
=
np.
array
(
[
6
,
2
,
13
,
10
]
)
plt.
plot
(
ypoints
,
'o:r'
)
plt.
show
(
)
The display result is as follows:

Line types:
| Line type markers | Description |
|---|---|
| '-' | Solid line |
| ':' | Dotted line |
| '--' | Dashed line |
| '-.' | Dash-dot line |
Color types:
| Color markers | Description |
|---|---|
| 'r' | Red |
| 'g' | Green |
| 'b' | Blue |
| 'c' | Cyan |
| 'm' | Magenta |
| 'y' | Yellow |
| 'k' | black |
| 'w' | white |
Marker size and color
We can customize the marker size and color using the following parameters respectively:
- markersize, abbreviated as ms: Defines the size of the marker.
- markerfacecolor, abbreviated as mfc: Defines the color inside the marker.
- markeredgecolor, abbreviated as mec: Defines the color of the marker edge.
Set the marker size:
Example
import
matplotlib.
pyplot
as
plt
import
numpy
as
np
ypoints
=
np.
array
(
[
6
,
2
,
13
,
10
]
)
plt.
plot
(
ypoints
,
marker
=
'o'
,
ms
=
20
)
plt.
show
(
)
The display result is as follows:

Set the marker edge color:
Example
import
matplotlib.
pyplot
as
plt
import
numpy
as
np
ypoints
=
np.
array
(
[
6
,
2
,
13
,
10
]
)
plt.
plot
(
ypoints
,
marker
=
'o'
,
ms
=
20
,
mec
=
'r'
)
plt.
show
(
)
The display result is as follows:

Set the marker inner color:
Example
import
matplotlib.
pyplot
as
plt
import
numpy
as
np
ypoints
=
np.
array
(
[
6
,
2
,
13
,
10
]
)
plt.
plot
(
ypoints
,
marker
=
'o'
,
ms
=
20
,
mfc
=
'r'
)
plt.
show
(
)
The display result is as follows:

Customize the marker inner and edge colors:
Example
import
matplotlib.
pyplot
as
plt
import
numpy
as
np
ypoints
=
np.
array
(
[
6
,
2
,
13
,
10
]
)
plt.
plot
(
ypoints
,
marker
=
'o'
,
ms
=
20
,
mec
=
'#4CAF50'
,
mfc
=
'#4CAF50'
)
plt.
show
(
)
The display result is as follows:






































