我在嘗試設置圖例條目的顏色時遇到了一些問題。我想選擇與他們所指的線相同的顏色。我在這里發布一個可運行的腳本import matplotlib.pyplot as pltx, 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'但是我在圖例文檔中看到labelcolor 應該作為參數。你有什么建議嗎?
1 回答

慕的地6264312
TA貢獻1817條經驗 獲得超6個贊
將 matplotlib 升級到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()
添加回答
舉報
0/150
提交
取消