# ValueError: 不存在编号为 1 的图形

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

## 根因

调用了 plt.figure(1) 或对已关闭（plt.close('all')）或从未创建的图形编号调用 plt.savefig。

## 版本兼容性

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

## 解决方案

1. **** (96% 成功率)
   ```
   fig = plt.figure(num=1, figsize=(6,4))
ax = fig.add_subplot(111)
ax.plot([1,2,3])
fig.savefig('out.png')
   ```
2. **** (97% 成功率)
   ```
   fig, ax = plt.subplots()
ax.plot([1,2,3])
fig.savefig('out.png')  # never rely on figure numbers
   ```

## 无效尝试

- **** — The figure genuinely does not exist; subsequent savefig calls will still fail. (85% 失败率)
- **** — draw() only redraws existing figures; it does not create one with a given number. (80% 失败率)
