The keyword argument marker
of the scatter()
function is used to set the shape of the markers. There are around 37 marker shapes available in Matplotlib, but the commonly used symbols are mentioned below:
Marker Value | Description | Symbol |
---|---|---|
"." | Point | • |
"," | Pixel | ⋅ |
"o" | Circle | ● |
"^" | Triangle Up | ▲ |
">" | Triangle Right | ▶ |
"v" | Triangle Down | ▼ |
"<" | Triangle Left | ◀ |
"s" | Square | ■ |
"*" | Star | ⁎ |
"+" | Plus | + |
"D" | Diamond | ◆ |
In the following example, we will draw a scatter plot having 10 data points. Here, we will set the marker to an upper triangle.
import matplotlib.pyplot as plt #Data Points x = [1, 1, 3, 2, 2, 3, 4, 5, 4, 7] y = [4, 3, 2, 4, 7, 4, 1, 10, 3, 2] #Marker Symbol symbol = "^" #Draw Scatter Plot plt.scatter(x, y, marker=symbol) #Show Scatter Plot plt.show()
Output
Let's set the marker to star in the below example.
import matplotlib.pyplot as plt #Data Points x = [1, 1, 3, 2, 2, 3, 4, 5, 4, 7] y = [4, 3, 2, 4, 7, 4, 1, 10, 3, 2] #Marker Symbol symbol = "*" #Draw Scatter Plot plt.scatter(x, y, marker=symbol) #Show Scatter Plot plt.show()
Output