1. 程式人生 > >Python第三方庫——Matplotlib_在同個figure中繪製多個圖並給出legend

Python第三方庫——Matplotlib_在同個figure中繪製多個圖並給出legend

import matplotlib.pyplot as plt

line1, = plt.plot([1,2,3], linestyle='--')
line2, = plt.plot([3,2,1], linewidth=4)

# Create a legend for the first line.
plt.legend([line1, line2], ["Line 1", "Line 2"], loc=1)
plt.show()

這裡寫圖片描述