# TypeError: rotation必须是数字或字符串，而不是列表

- **ID:** `python/matplotlib-tick-label-rotation-error`
- **领域:** python
- **类别:** type_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

向set_xticklabels()等函数传递了旋转值列表，但该函数期望为所有标签设置一个标量值，或为标签列表配合标量旋转。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.8 | active | — | — |
| 3.9 | active | — | — |

## 解决方案

1. **Use a scalar rotation value** (95% 成功率)
   ```
   ax.set_xticklabels(labels, rotation=45)
   ```
2. **Apply rotation individually using a loop** (90% 成功率)
   ```
   for label in ax.get_xticklabels(): label.set_rotation(45)
   ```

## 无效尝试

- **Using a tuple instead of a list** — Tuples are also not accepted; rotation must be a scalar. (80% 失败率)
- **Setting rotation via rcParams for all ticks** — This changes default but doesn't fix the TypeError from passing a list. (70% 失败率)
