# TypeError: 'ticks'必须是数字序列或None，但得到了字符串列表。

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

## 根因

向colorbar()的ticks参数直接传递了字符串标签，但该参数需要数字位置。

## 版本兼容性

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

## 解决方案

1. **Set numeric tick positions and then set tick labels separately** (95% 成功率)
   ```
   cbar = plt.colorbar(); cbar.set_ticks([0, 0.5, 1]); cbar.set_ticklabels(['low', 'mid', 'high'])
   ```
2. **Use the format parameter for simple formatting** (90% 成功率)
   ```
   cbar = plt.colorbar(ticks=[0, 0.5, 1], format='%.2f')
   ```

## 无效尝试

- **Using a list of integers but with non-monotonic order** — Ticks must be monotonic; non-monotonic values may work but cause visual issues. (60% 失败率)
- **Setting tick labels without setting tick positions** — The error is about the ticks argument; positions must be numeric. (80% 失败率)
