Dùng labelspacing trong plt.legend() để thay đổi khoảng cách dọc giữa các mục legend.
- Vẽ 3 đường với label 'Label 1', 'Label 2', 'Label 3'.
- space = 2.
- plt.legend(labelspacing=space).
- show().
Ví dụ
from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True plt.plot([0, 1], [0, 1.0], label='Label 1') plt.plot([0, 1], [0, 1.1], label='Label 2') plt.plot([0, 1], [0, 1.2], label='Label 3') space = 2 plt.legend(labelspacing=space) plt.show()
Kết quả
Legend 3 mục với khoảng cách dọc giữa các dòng gấp 2 lần mặc định.