python
type_error
ai_generated
true
TypeError: rotation必须是数字或字符串,而不是列表
TypeError: rotation must be a number or string, not a list
ID: python/matplotlib-tick-label-rotation-error
80%修复率
82%置信度
0证据数
2024-04-15首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.8 | active | — | — | — |
| 3.9 | active | — | — | — |
根因分析
向set_xticklabels()等函数传递了旋转值列表,但该函数期望为所有标签设置一个标量值,或为标签列表配合标量旋转。
English
Passing a list of rotation values to set_xticklabels() or similar, which expects a single value for all labels or a list of labels with a scalar rotation.
解决方案
-
95% 成功率 Use a scalar rotation value
ax.set_xticklabels(labels, rotation=45)
-
90% 成功率 Apply rotation individually using a loop
for label in ax.get_xticklabels(): label.set_rotation(45)
无效尝试
常见但无效的做法:
-
Using a tuple instead of a list
80% 失败
Tuples are also not accepted; rotation must be a scalar.
-
Setting rotation via rcParams for all ticks
70% 失败
This changes default but doesn't fix the TypeError from passing a list.