# UserWarning: 未找到带标签的图元可放入图例。注意，当无参数调用 legend() 时，标签以下划线开头的图元会被忽略。

- **ID:** `python/matplotlib-legend-no-handles`
- **领域:** python
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

调用 ax.legend() 时没有任何已绘制的图元设置了 label，或所有标签以下划线开头。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.x | active | — | — |

## 解决方案

1. **** (97% 成功率)
   ```
   ax.plot(x, y1, label='series A')
ax.plot(x, y2, label='series B')
ax.legend()
   ```
2. **** (94% 成功率)
   ```
   lines = [ax.plot(x, y1)[0], ax.plot(x, y2)[0]]
ax.legend(lines, ['A', 'B'])
   ```

## 无效尝试

- **** — There are still no labeled artists to display. (95% 失败率)
- **** — A title is not a legend and does not label the plotted series. (90% 失败率)
