Matplotlib - 中文字体
2020-08-10 13:22
1066 查看
title: Matplotlib - 中文字体
categories:
- python
- Matplotlib
tags: - python
- Matplotlib
- Computer Drawing
首先,Matplotlib本身是不支持中文的。
因此我们需要自己下载中文字体;
方法:
使用思源黑体,思源黑体是 Adobe 与 Google 推出的一款开源字体。
下载地址:
官网:https://source.typekit.com/source-han-serif/cn/
Github地址:https://github.com/adobe-fonts/source-han-sans/tree/release/OTF/SimplifiedChinese
可以下载个 OTF 字体,比如 SourceHanSansSC-Bold.otf,将该文件文件放在当前执行的代码文件中:
import numpy as np from matplotlib import pyplot as plt import matplotlib from matplotlib.font_manager import FontProperties # fname 为 你下载的字体库路径,注意 SourceHanSansSC-Bold.otf 字体的路径 zhfont1 = FontProperties(fname="SourceHanSansSC-Bold.otf",size = 15) x = np.arange(1, 11) y = 2 * x + 5 plt.title("测试", fontproperties=zhfont1) # fontproperties 设置中文显示,fontsize 设置字体大小 plt.xlabel("x 轴", fontproperties=zhfont1) plt.ylabel("y 轴", fontproperties=zhfont1) plt.plot(x, y) plt.show()
运行结果:
相关文章推荐
- matplotlib中中文字体配置
- matplotlib解决中文乱码问题,设置字体两种方式
- python matplotlib绘图使用中文字体
- matplotlib制图解决中文字体问题
- Matplotlib/Seaborn中文字体乱码问题解决-Windows+Mac
- Matplotlib 中文字体设置
- python画图包seaborn和matplotlib中文字体显示(针对windows系统,,使用ipython notebook)
- Matplotlib的中文字体显示为方块的问题
- Pandas matplotlib 画图无法显示中文字体的问题
- matplotlib命令与格式:系统字体与显示中文
- python matplotlib 中文字体设置
- python 画图 matplotlib 插入中文字体 for mac
- matplotlib显示中文字体
- python matplotlib 中文字体设置
- matplotlib 中文字体问题
- 在嵌入式设备上(树莓派)动态显示带有中文字体的图片(采用matplotlib绘图)
- linux 下matplotlib 无法显示中文字体的问题
- matplotlib设置中文字体
- Windows-Python-matplotlib-中文字体显示
- 使用matplotlib绘图时中文字体的解决方案