{
  "id": "python/matplotlib-legend-no-handles",
  "signature": "UserWarning: No artists with labels found to put in legend. Note that artists whose label start with an underscore are ignored when legend() is called with no argument.",
  "signature_zh": "UserWarning: 未找到带标签的图元可放入图例。注意，当无参数调用 legend() 时，标签以下划线开头的图元会被忽略。",
  "regex": "UserWarning:\\ No\\ artists\\ with\\ labels\\ found\\ to\\ put\\ in\\ legend\\.\\ Note\\ that\\ artists\\ whose\\ label\\ start\\ with\\ an\\ underscore\\ are\\ ignored\\ when\\ legend\\(\\)\\ is\\ called\\ with\\ no\\ argument\\.",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "Calling ax.legend() without any plotted artists having a label set, or all labels starting with '_'.",
  "root_cause_type": "generic",
  "root_cause_zh": "调用 ax.legend() 时没有任何已绘制的图元设置了 label，或所有标签以下划线开头。",
  "versions": [
    {
      "version": "3.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "There are still no labeled artists to display.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "A title is not a legend and does not label the plotted series.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.97,
      "how": "ax.plot(x, y1, label='series A')\nax.plot(x, y2, label='series B')\nax.legend()",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.94,
      "how": "lines = [ax.plot(x, y1)[0], ax.plot(x, y2)[0]]\nax.legend(lines, ['A', 'B'])",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": null,
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.87,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-08-25",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}