I'm having some trouble trying to set the color of legend entries. I want to select the same color as the line they are referring to. Here i post a runable script
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()
And that's the error I'm getting
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'
However I saw in the legend documentation that labelcolor should work as argument. Do you have any suggestions?
Thank you in advance
Upgrade matplotlib to version 3.3.0
Then try it again.
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()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.