set_title() got an unexpected keyword argument 'fontsize'为被返回了
时间: 2023-07-30 17:09:05 浏览: 379
这个错误通常会出现在使用matplotlib库设置标题时,因为`set_title()`方法不接受`fontsize`这个参数。解决方法可以是使用`set_fontsize()`方法来设置字体大小,例如:
```
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.plot([1, 2, 3], [4, 5, 6])
ax.set_title('My Title')
ax.title.set_fontsize(16)
plt.show()
```
这里的`ax.title.set_fontsize(16)`可以设置标题的字体大小为16。
相关问题
set_title() got an unexpected keyword argument 'fontsize'
The error message "set_title() got an unexpected keyword argument 'fontsize'" suggests that the method `set_title()` was called with an argument `fontsize` which is not recognized by the method.
This error could occur if you are using an outdated version of matplotlib or if you are using the method incorrectly.
To resolve this issue, you can try updating your matplotlib version to the latest one. If that does not work, you can check the documentation of the `set_title()` method to see if there is a different way to set the font size. Alternatively, you can use a different method to set the title of your plot that supports the `fontsize` argument.
set_ticks() got an unexpected keyword argument 'fontsize'
根据提供的引用,出现了一个TypeError,提示set_ticks()方法不支持fontsize参数。这是因为set_ticks()方法不接受fontsize参数,因此需要使用其他方法来调整刻度标签的字体大小。可以使用set_tick_params()方法来调整刻度标签的字体大小,示例如下:
```python
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
# 设置x轴刻度标签的字体大小为14
ax.tick_params(axis='x', labelsize=14)
plt.show()
```
此外,还可以使用set_xticklabels()和set_yticklabels()方法来设置刻度标签的字体大小,示例如下:
```python
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
# 获取x轴刻度标签
xticks = ax.get_xticklabels()
# 设置x轴刻度标签的字体大小为14
for xtick in xticks:
xtick.set_fontsize(14)
plt.show()
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)