matlplotlib绘图 之 函数legend()
添加图例的两种方法 1.【推荐使用】在plot函数中增加label参数,然后在后面加上plt.legend() plt.plot(x, x*3.0, label='Fast') plt.plot(x, x/3.0, label='Slow') plt.legend() 2.legend方法中传入字符串列表 plt.plot(x,np.sin(x),x,np.cos(x)) plt.legend(["sin","cos"]) 接下来是两篇文章的阅读笔记(将自己不懂的地方标注了一下) 第一篇: 用python的matplotlib画图时,往往需要加图例说明。如果不设置任何参数,默认是加到图像的内侧的最佳位置。 如果需要将该legend移到图像外侧,有多种方法,这里介绍一种。 在plt.legend()函数中加入若干参数:plt.legend(bbox_to_anchor=(num1, num2), loc=num3, borderaxespad=num4),只要加上这些参数并给他们设置一定的值,则就会将图例放在外面。 具体设置参考文章:https://blog.csdn.net/Poul_henry/article/details/82533569 第二篇:原文链接:https://blog.csdn.net/Poul_henry/article/details/88311964