在 Matplotlib 中,marker
參數用於設定折線圖或散點圖中點的樣式。不同的 marker 可以幫助區分不同的線或資料點。
Marker | 說明 |
---|---|
'o' |
圓形 (circle) |
'^' |
上三角形 (triangle up) |
'v' |
下三角形 (triangle down) |
's' |
方形 (square) |
'p' |
五邊形 (pentagon) |
'*' |
星號 (star) |
'+' |
加號 (plus) |
'x' |
叉號 (x) |
'D' |
菱形 (diamond) |
'd' |
小菱形 (thin diamond) |
'h' |
六邊形 1 (hexagon1) |
'H' |
六邊形 2 (hexagon2) |
'<' |
左三角形 (triangle left) |
'>' |
右三角形 (triangle right) |
`' | '` |
'_' |
水平線 (hline) |
'.' |
點 (point) |
import matplotlib.pyplot as plt
x = [1, 2, 3, 4, 5]
y1 = [2, 3, 1, 4, 2]
y2 = [3, 2, 4, 1, 3]
y3 = [1, 4, 2, 3, 5]
plt.plot(x, y1, marker='o', label='circle')
plt.plot(x, y2, marker='^', label='triangle up')
plt.plot(x, y3, marker='s', label='square')
plt.xlabel('X 軸')
plt.ylabel('Y 軸')
plt.title('不同 Marker 範例')
plt.legend()
plt.grid(True)
plt.show()