欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2022-03-15 15:02:44
原文链接:http://www.juzicode.com/archives/2486错误提示:使用matplotlib legend提示:ValueError: Unrecognized location ‘upper’. Valid locations areTraceback (most recent call last): File "09-plt-step.py", line 30, in plt.legend(title='参数where:'...

原文链接: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

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

可能原因:

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

本文地址:https://blog.csdn.net/juzicode00/article/details/110939608