matplotlib 不显示以下划线 _ 开头的图例

matplolib doesn't show legend starting with underscore _

我在 python 中有以下代码:

import matplotlib.pyplot as plt
plt.plot([1,2,3],label="_test")
plt.legend()
plt.show()

而当运行它时,会出现以下警告:

/usr/lib/pymodules/python2.7/matplotlib/axes.py:4486: UserWarning: No labeled objects found. Use label='...' kwarg on individual plots.
warnings.warn("No labeled objects found. "

没有图例出现。

在尝试删除标签开头的“_”后,问题似乎出在此处。

有人知道为什么会这样吗?它是已知的 voluntary/logical 功能、不便之处还是错误?是否在任何地方都有报道,因为我在 http://matplotlib.org/users/legend_guide.html 上找不到任何相关信息?它是特定于图例的标签还是与其他一些标签一起出现(可能是标题,xylabels?)

非常感谢您的帮助

the documentation 中记录了 legend,它是从您链接到的页面链接的:

Specific lines can be excluded from the automatic legend element selection by defining a label starting with an underscore.