python
config_error
ai_generated
true
KeyError: 'font.size'不是有效的rc参数。请参阅rcParams.keys()获取有效参数。
KeyError: 'font.size' is not a valid rc parameter. See rcParams.keys() for valid parameters.
ID: python/matplotlib-rcparams-typo-error
80%修复率
85%置信度
0证据数
2024-03-20首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.7 | active | — | — | — |
| 3.8 | active | — | — | — |
根因分析
rcParams键拼写错误;正确的键是'font.size',但用户可能拼写为'font.szie'或'fontsize'。
English
Typo in rcParams key; correct key is 'font.size' but user might have typed 'font.size' with a dot (which is correct) or a misspelling like 'font.szie'. Actually 'font.size' is valid; the error occurs when the key is misspelled (e.g., 'font.szie' or 'fontsize').
解决方案
-
95% 成功率 Use the exact key from documentation
plt.rcParams['font.size'] = 12
-
90% 成功率 List all rcParams to find the correct spelling
print([key for key in plt.rcParams.keys() if 'font' in key])
无效尝试
常见但无效的做法:
-
Using 'fontsize' without dot
90% 失败
The key must have a dot separating group and property; 'fontsize' is not valid.
-
Using 'Font.size' with capital letters
85% 失败
Keys are case-sensitive; 'Font.size' is not valid.