溫馨提示×

Matplotlib中怎么設(shè)置圖例的標記樣式

小億
92
2024-05-11 19:30:47
欄目: 編程語言

在Matplotlib中,可以使用marker參數(shù)來設(shè)置圖例的標記樣式。例如,可以使用以下代碼來設(shè)置圖例的標記樣式為圓形:

import matplotlib.pyplot as plt

x = [1, 2, 3, 4, 5]
y = [2, 3, 5, 7, 11]

plt.plot(x, y, label='Data', marker='o')
plt.legend()
plt.show()

在上面的代碼中,marker='o'表示設(shè)置圖例的標記樣式為圓形??梢愿鶕?jù)需要修改marker參數(shù)的值來設(shè)置其他樣式,如矩形(marker='s')、三角形(marker='^')等。

0