Understanding Matplotlib Markers
Matplotlib Markers are the symbols that are used to represent the data points in a plot.
The purpose of this article is to describe Matplotlib markers in depth, including their types, features, and functionality with examples.
Matplotlib Markers Options
Matplotlib provides a wide range of basic marker options that can be used to represent data points in a plot.
Some of the basic marker options available in Matplotlib are:
- Circle: ‘o‘
- Star: ‘*‘
- Diamond: ‘d‘
- Triangle: ‘^‘
With the keyword argument marker, you can highlight each point with a particular marker:
In the example below, display all points with a circle as follows:
Example: 
Set marker = ‘o‘ to show the coordinates of the following diagram:
Example: 
In the example below, show all points with a star as follows:
Example: 
Assign marker = ‘*‘ to display the coordinates of the following diagram:
Example: 
Here are some Matplotlib markers with examples you can select from:
Markers | Overview | Examples |
‘o’ | Circle | Execute |
‘*’ | Star | Execute |
‘.’ | Point | Execute |
‘,’ | Pixel | Execute |
‘x’ | X | Execute |
‘X’ | X (filled) | Execute |
‘+’ | Plus | Execute |
‘P’ | Plus (filled) | Execute |
‘s’ | Square | Execute |
‘D’ | Diamond | Execute |
‘d’ | Diamond (thin) | Execute |
‘p’ | Pentagon | Execute |
‘H’ | Hexagon | Execute |
‘h’ | Hexagon | Execute |
‘v’ | Triangle Down | Execute |
‘^’ | Triangle Up | Execute |
‘<‘ | Triangle Left | Execute |
‘>’ | Triangle Right | Execute |
‘1’ | Tri Down | Execute |
‘2’ | Tri Up | Execute |
‘3’ | Tri Left | Execute |
‘4’ | Tri Right | Execute |
‘|’ | Vline | Execute |
‘_’ | Hline | Execute |
Format Strings fmt
It is also possible to indicate the marker through the shortcut string notation parameter as well.
This parameter is also referred to as fmt, and is represented as follows:
marker|line|color
Display the following diagram with dotted line in blue and also apply the ‘P‘ marker:
Example: 
Utlize the ‘>‘ marker and green color in the below example:
Example: 
The marker type can be selected from any of the markers listed in the Marker Reference section.
There are several possible values for the line:
Line Syntax | Overview | Examples |
‘-‘ | Solid line | Execute |
‘:’ | Dotted line | Execute |
‘–‘ | Dashed line | Execute |
‘-.’ | Dashed/dotted line | Execute |
You can select a color from the following short color names:
Color Reference
Color Syntax | Overview | Examples |
‘r’ | Red | Execute |
‘g’ | Green | Execute |
‘b’ | Blue | Execute |
‘c’ | Cyan | Execute |
‘m’ | Magenta | Execute |
‘y’ | Yellow | Execute |
‘k’ | Black | Execute |
‘w’ | White | Execute |
Marker Size
For setting the marker size, you can provide the keyword argument markersize or the simpler alternative, ms:
Implement the ms argument in the following example:
Example: 
Apply the fmt parameter with ms = 20:
Example: 
Marker Color
To modify the color of the edge of the markers, you can either provide the keyword argument markeredgecolor or the simpler mec parameter:
Utilize the mec argument in the following example:
Example: 
First set the mec = ‘b’, then assign marker edge width (mec) = 6:
Example: 
If you want to change the color within the edge of the markers, you can invoke the keyword argument markerfacecolor or the more concise mfc.
Assign face color to the following diagram marker as follows:
Example: 
Insert the magenta color inside the edge of the below diagram marker:
Example: 
To color the entire marker, utilize each of the mec and mfc arguments:
Modify the marker face and edge color to yellow:
Example: 
First assign the marker face and edge color to black, then increase the width of the line:
Example: 
In addition to Hexadecimal color values, you can also utilize:
In the following example, implement the customized hexadecimal color:
Example: 
Apply these two colors ‘#ffcc00‘ and ‘#ff1ac6‘ in the below diagram:
Example: 
You can also utlize 140 supported color names which defined in matplotlib markers document.
Put a mark on each point with a color called “GreenYellow” and “Black”:
Example: 
Apply ‘PowderBlue’ color to marker edge and ‘Gray’ to marker face:s
Example: 
Example Explanation
The y_plane array is created using NumPy to store some example data.
Then, pt.plot() function is used to create a line plot of the y_plane array. The ‘*–b‘ argument specifies the marker style and color of the plot, where ‘*‘ indicates the marker style as a star, — indicates the line style as dashed, and ‘b‘ indicates the color as blue.
- The ms parameter sets the size of the marker to 30.
- mec parameter sets the marker edge color to ‘PowderBlue’.
- mew parameter sets the width of the marker edge to 4.
- mfc parameter sets the marker face color to ‘Gray’.
Finally, the pt.show() function is called to display the plot.
Matplotlib Markers Benefits
Matplotlib markers offer various benefits for effective data visualization.
- Markers help to distinguish data points in a plot, making data more readable and understandable.
- Matplotlib markers are customizable and allow users to choose shape, size, color, edge color, and line style, enabling them to tailor markers to specific needs.
- The versatility of Matplotlib markers makes them suitable for various plot types such as scatter plots, line plots, and bar plots, which can lead to diverse visualizations with consistent data point representation.
- Matplotlib markers are flexible and can be used with other plotting functions and tools to create more complex visualizations.
- Matplotlib markers ensure compatibility with other Matplotlib functions and tools, which simplifies integrating markers into existing code and workflows.