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

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