{
  "id": "python/matplotlib-savefig-dpi-error",
  "signature": "ValueError: dpi must be a positive number, got -100",
  "signature_zh": "ValueError: dpi必须是正数，但得到了-100",
  "regex": "ValueError:\\ dpi\\ must\\ be\\ a\\ positive\\ number,\\ got\\ \\-100",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "Passing a negative or zero value for the dpi parameter in savefig() or figure creation.",
  "root_cause_type": "generic",
  "root_cause_zh": "在savefig()或创建图形时，为dpi参数传递了负数或零值。",
  "versions": [
    {
      "version": "3.7",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "3.8",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Using a very large positive DPI like 10000",
      "why_fails": "While it doesn't raise an error, it may cause memory issues or produce excessively large files.",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    },
    {
      "action": "Passing dpi as a string like '300'",
      "why_fails": "dpi must be a number, not a string; this raises a different TypeError.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Use a positive integer for dpi",
      "success_rate": 0.95,
      "how": "plt.savefig('plot.png', dpi=300)",
      "condition": "",
      "sources": []
    },
    {
      "action": "Check the variable value before passing",
      "success_rate": 0.9,
      "how": "dpi_value = 300; if dpi_value > 0: plt.savefig('plot.png', dpi=dpi_value)",
      "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.86,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-03-05",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}