Sau khi tạo legend bằng plt.legend(), bạn có thể sửa tiêu đề legend bằng phương thức set_title() trên đối tượng legend trả về.
Ví dụ minh họa
from matplotlib import pyplot as plt
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
plt.plot([1, 3, 4, 5, 2, 1], [3, 4, 1, 3, 0, 1], label="line plot", color='red', lw=0.5)
leg = plt.legend(loc="upper right")
leg.set_title("Tiêu đề")
plt.show()
Kết quả đầu ra
