matplotlib设置label位置(matplotlib.pyplot.legend)

通过legend方法设置坐标轴中图形的label位置。

设置前如图所示:


image.png

修改标签位置到右下角:

plt.legend(loc='lower right', fontsize=40) # 标签位置

结果如下:


image.png

完整代码:

def print_pic(pic_name, x, y1, y2):
    font_size=50
    plt.style.use('ggplot')
    fig=plt.figure(figsize=(25,20))
    plt.xlabel('x',fontsize=font_size)
    plt.ylabel('y',fontsize=font_size)
    plt.plot(x, y1, label='label1',linewidth=4)
    plt.plot(x, y2, label='label2',linewidth=4)
    plt.title(pic_name,fontsize=font_size)
    plt.legend(loc='lower right', fontsize=40) # 标签位置
    plt.savefig(pic_name,dpi=300)
    plt.show()

参考文献


本文作者: seawish
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 3.0 许可协议。转载请注明出处!

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容