“没有发现有标签的艺术家可以加入传奇。”更改 pyplot 中的图例大小时出错

问题描述 投票:0回答:2

我想在 Pyplot 中使我的图例尺寸更大。我用这个答案来做到这一点。这是我的代码。

import matplotlib.pyplot as plt
import seaborn as sns

sns.set_style("whitegrid")
plt.rcParams['figure.figsize'] = [15, 7]

lst = [1,2,3,4,5,6,7,8,9,8,7,6,5,4,3,4,5,6]

plt.plot(lst)
plt.legend(fontsize="x-large") # Here I make it bigger but doesn't work
plt.legend(["This is my legend"])
plt.ylabel('some numbers')
plt.show()

我收到此警告,但我不知道出了什么问题。我不明白这里的“艺术家”是什么意思。

没有发现有标签的艺术家加入传奇。请注意,当不带参数调用 legend() 时,标签以下划线开头的艺术家将被忽略。

python matplotlib legend
2个回答
10
投票

“艺术家”是来自 matplotlib 的术语:

https://matplotlib.org/stable/tutorials/intermediate/artists.html

大概错误消息意味着图例中没有可以更改字体大小的项目。

也许将

fontsize
参数传递给创建图例的 same
plt.legend
调用,或者在创建图例后调用
plt.legend(fontsize=...)
after


0
投票

此警告表示尝试创建图例,但没有任何标签显示为图例。解决方案是按照 OP 观察到的那样在

legend()
调用中传递标签:

import matplotlib.pyplot as plt
lst = [1, 3, 2]

plt.plot(lst)
plt.legend(["This is my legend"], fontsize="x-large")

或者在

plot
调用中传递标签并稍后绘制图例。

plt.plot(lst, label="This is my legend")  # <--- the label corresponds to this plot
plt.legend(fontsize="x-large")            # <--- the above plot's label is drawn in the legend
© www.soinside.com 2019 - 2024. All rights reserved.