Matplotlib使用笔记----中文字体显示
程序员文章站
2022-03-19 22:16:22
...
1. 查询matplotlib系统中文字体
from matplotlib.font_manager import fontManager
import os
fonts = [font.name for font in fontManager.ttflist if os.path.exists(font.fname) and os.stat(font.fname).st_size>1e6]
for font in fonts:
print(font)
2. 设置字体显示中文
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签
plt.rcParams['axes.unicode_minus']=False #用来正常显示负号
plt.title('中文')
3. 修改rcParams字体来实现
rcParams的属性:
‘font.family’ 用于显示字体的名字
‘font.style’ 字体风格,正常’normal’ 或斜体’italic’
‘font.size’ 字体大小,整数字号或者’large’ ‘x-small’
‘font.family’ 用于显示字体的名字
‘font.style’ 字体风格,正常’normal’ 或斜体’italic’
‘font.size’ 字体大小,整数字号或者’large’ ‘x-small’
import matplotlib.pyplot as plt
import matplotlib
matplotlib.rcParams['font.family'] = 'STSong'
matplotlib.rcParams['font.size'] = 20
plt.title('中文')
4. matplotlib调用windows系统字体
只希望在某地方绘制中文字符,不改变别的地方的字体import matplotlib.pyplot as plt
from matplotlib.font_manager import FontProperties
font = FontProperties(fname=r"c:\windows\fonts\msyh.ttc", size=10)
plt.title('中文标题',fontproperties=font)
推荐阅读
-
笔记本使用OLED显示屏真的好么?详解OLED显示屏和LED显示屏区别
-
Python学习笔记--使用matplotlib绘制饼状图
-
使用matplotlib库实现图形局部数据放大显示的实践
-
Python使用Matplotlib模块时坐标轴标题中文及各种特殊符号显示方法
-
使用matplotlib库实现图形局部数据放大显示的实践
-
笔记本使用OLED显示屏真的好么?详解OLED显示屏和LED显示屏区别
-
Python使用matplotlib绘制多个图形单独显示的方法示例
-
Python使用matplotlib绘图无法显示中文问题的解决方法
-
OpenCV学习笔记(一):使用opencv读取摄像头并实时显示
-
从php获取json数据使用js读取显示到网页笔记