label=在每个
plot()呼叫中添加一个,然后呼叫
legend(loc='upperleft')。
考虑以下示例(使用Python 3.8.0测试):
import numpy as npimport matplotlib.pyplot as pltx = np.linspace(0, 20, 1000)y1 = np.sin(x)y2 = np.cos(x)plt.plot(x, y1, "-b", label="sine")plt.plot(x, y2, "-r", label="cosine")plt.legend(loc="upper left")plt.ylim(-1.5, 2.0)plt.show()
从本教程中略作修改:http
:
//jakevdp.github.io/mpl_tutorial/tutorial_pages/tut1.html
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)