如何解决matplotlib.axes.Axes.legend无法识别labelcolor作为参数
尝试设置图例条目的颜色时遇到麻烦。我要选择 与他们所指的线条颜色相同。在这里,我发布了一个可运行的脚本
import matplotlib.pyplot as plt
x,y = [1,2],[1,2]
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(x,y,label='test',color='r')
ax.legend(labelcolor='r')
plt.show()
那就是我得到的错误
Traceback (most recent call last):
File "test.py",line 11,in <module>
ax.legend(labelcolor='r')
File "/home/username/anaconda3/lib/python3.7/site-packages/matplotlib/axes/_axes.py",line 406,in legend
self.legend_ = mlegend.Legend(self,handles,labels,**kwargs)
TypeError: __init__() got an unexpected keyword argument 'labelcolor'
但是我在legend documentation中看到labelcolor应该作为参数。 你有什么建议吗?
提前谢谢
解决方法
将matplotlib升级到version 3.3.0
然后再试一次。
import matplotlib.pyplot as plt
x,y = [1,2],[1,2]
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(x,y,label='test',color='r')
ax.legend(title='Guide',labelcolor='red')
plt.show()
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。