Python错误集锦:matplotlib legend提示:ValueError: Unrecognized location ‘upper’. Valid locations are

原文链接:http://www.juzicode.com/archives/2486

错误提示:

使用matplotlib legend提示:ValueError: Unrecognized location ‘upper’. Valid locations are

Traceback (most recent call last):
  File "09-plt-step.py", line 30, in <module>
    plt.legend(title='参数where:',fontsize='xx-small',loc='upper')
  File "D:\Python\Python38\lib\site-packages\matplotlib\pyplot.py", line 2738, in legend
    return gca().legend(*args, **kwargs)
  File "D:\Python\Python38\lib\site-packages\matplotlib\axes\_axes.py", line 417, in legend
    self.legend_ = mlegend.Legend(self, handles, labels, **kwargs)
  File "D:\Python\Python38\lib\site-packages\matplotlib\legend.py", line 455, in __init__
    raise ValueError(
ValueError: Unrecognized location 'upper'. Valid locations are
        best
        upper right
        upper left
        lower left
        lower right
        right
        center left
        center right
        lower center
        upper center
        center

错误原因:

1、使用matplotlib的legend图例说明是,说明位置参数loc=’upper’非法,没有’upper’类型的位置值

解决方法:

1、通过错误提示找到合法的位置值:

        best
        upper right
        upper left
        lower left
        lower right
        right
        center left
        center right
        lower center
        upper center
        center

关注微信公众号:“桔子code”,欢迎后台留言撩我,我会尽我所能为你解惑Python,C等编程知识

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注