plt 设置 汉字字体有哪些
时间: 2023-05-27 16:01:53 浏览: 55
1. SimHei:黑体
2. Microsoft YaHei:微软雅黑
3. KaiTi:楷体
4. FangSong:仿宋
5. SimSun:宋体
6. NSimSun:新宋体
7. MingLiU:细明体
8. PMingLiU:新细明体
9. Arial Unicode MS:Arial Unicode MS
10. STHeiti:华文黑体
相关问题
plt.plot字体设置
要设置 `plt.plot` 中的字体,可以使用 `fontname` 参数来指定字体名称。以下是一个示例代码:
```python
import matplotlib.pyplot as plt
# 设置字体名称
font_name = 'SimHei' # 指定为中文宋体
# 创建示例数据
x = [1, 2, 3, 4, 5]
y = [1, 4, 9, 16, 25]
# 绘制图形
plt.plot(x, y)
# 设置坐标轴标签的字体
plt.xlabel('X轴', fontname=font_name)
plt.ylabel('Y轴', fontname=font_name)
# 设置图标题的字体
plt.title('示例图', fontname=font_name)
# 显示图形
plt.show()
```
在上述代码中,我们使用 `fontname` 参数来设置字体名称为 `'SimHei'`,这是一个常用的中文字体。你可以根据需要选择其他字体。
plt.plot设置字体类别
可以使用plt.rcParams来设置字体类别,具体步骤如下:
```python
import matplotlib.pyplot as plt
# 设置字体为SimHei显示中文
plt.rcParams['font.sans-serif'] = ['SimHei']
# 绘制图形
plt.plot([1, 2, 3, 4], [1, 4, 9, 16])
# 显示图形
plt.show()
```
在上述代码中,我们使用plt.rcParams['font.sans-serif'] = ['SimHei']将字体设置为SimHei,从而实现了中文显示。如果需要设置其他字体,只需要将SimHei替换为其他字体即可。