{
  "id": "python/matplotlib-savefig-no-fignum",
  "signature": "ValueError: No figure with number 1 exists",
  "signature_zh": "ValueError: 不存在编号为 1 的图形",
  "regex": "ValueError:\\ No\\ figure\\ with\\ number\\ 1\\ exists",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "Calling plt.figure(1) or plt.savefig on a figure number that was closed (plt.close('all')) or never created.",
  "root_cause_type": "generic",
  "root_cause_zh": "调用了 plt.figure(1) 或对已关闭（plt.close('all')）或从未创建的图形编号调用 plt.savefig。",
  "versions": [
    {
      "version": "3.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "The figure genuinely does not exist; subsequent savefig calls will still fail.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "draw() only redraws existing figures; it does not create one with a given number.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.96,
      "how": "fig = plt.figure(num=1, figsize=(6,4))\nax = fig.add_subplot(111)\nax.plot([1,2,3])\nfig.savefig('out.png')",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.97,
      "how": "fig, ax = plt.subplots()\nax.plot([1,2,3])\nfig.savefig('out.png')  # never rely on figure numbers",
      "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.85,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-10-14",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}