matplotlib设置字号
时间: 2024-04-25 10:18:16 浏览: 84
在matplotlib中设置字号可以通过以下几种方式实现:
1. 使用rcParams全局设置字号:
```python
import matplotlib.pyplot as plt
plt.rcParams['font.size'] = 12 # 设置全局字号为12
```
2. 在特定的图形对象上设置字号:
```python
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.set_title('Title', fontsize=14) # 设置标题字号为14
ax.set_xlabel('X Label', fontsize=12) # 设置X轴标签字号为12
ax.set_ylabel('Y Label', fontsize=12) # 设置Y轴标签字号为12
```
3. 使用字体对象设置字号:
```python
import matplotlib.pyplot as plt
from matplotlib.font_manager import FontProperties
font = FontProperties(size=12) # 创建一个字体对象,设置字号为12
plt.title('Title', fontproperties=font) # 设置标题字号为12
plt.xlabel('X Label', fontproperties=font) # 设置X轴标签字号为12
plt.ylabel('Y Label', fontproperties=font) # 设置Y轴标签字号为12
```
以上是几种常用的设置matplotlib字号的方法。你可以根据需要选择其中一种方式来设置字号。
阅读全文
相关推荐


















