matplotlib中中文字体配置
2020-02-14 00:37
435 查看
解决方式1:利用matplotlib的字体管理工具font_manager---->缺点:每次必须要进行设置
import matplotlib.pyplot as plt from matplotlib.font_manager import FontProperties font = FontProperties(fname='Desktop/simhei.ttf',size=20) # 前提是对应路径下有你想要使用的字体文件 # 1.设置画布 plt.figure(figsize=(20,8)) x = range(11,31) y = [1,0,1,1,2,4,3,2,3,4,4,5,6,5,4,3,3,1,1,1] # 2.绘制折线图 plt.plot(x,y,marker='o',color='blue',linestyle=':',alpha=0.5) # 3.设置x轴描述信息 plt.xlabel('年龄',color='blue',fontproperties=font) # 4.设置y轴描述信息 plt.ylabel('朋友个数',color='blue',fontproperties=font) plt.show()
解决方式二:更改matplotlib字体配置文件
1). 找到matplotlib对应的安装目录和缓存目录;对应命令:sudo fing / -name '*matplotlib'--->指在当前路径下找含有matplotlib字样的路径,如下图
2).进入安装目录,再进入到对应的mpl-data/fonts/ttf路径下,将你准备好的字体文件拷贝到此目录,如下图
3).切换回mpl-data路径下,打开matplotlibrc文件,做如下图的配置
4).进入第一步找到的缓存目录,删除掉其中的.json文件和.cache文件
5).在jupyter中重新载入内核,即刷新,然后再运行即可正常显示中文,如下图
转载于:https://www.cnblogs.com/houzichiguodong/p/9090204.html
- 点赞
- 收藏
- 分享
- 文章举报
相关文章推荐
- linux 下matplotlib 无法显示中文字体的问题
- matplotlib显示中文字体
- Matplotlib/Seaborn中文字体乱码问题解决-Windows+Mac
- python matplotlib绘图使用中文字体
- Python在Matplotlib图中显示中文字体的操作方法
- 使用matplotlib绘图时中文字体的解决方案
- python matplotlib 中文字体设置
- 在嵌入式设备上(树莓派)动态显示带有中文字体的图片(采用matplotlib绘图)
- Matplotlib 中文用户指南 4.4 默认字体
- python 画图 matplotlib 插入中文字体 for mac
- ubuntu下matplotlib中文字体的设置
- Matplotlib 中文字体设置
- python matplotlib 中文字体设置
- Linux/MacOS下matplotlib能正常显示的中文字体选择
- Windows-Python-matplotlib-中文字体显示
- Matplotlib使用笔记----中文字体显示
- 修改配置文件matplotlibrc,让Matplotlib显示中文
- python画图包seaborn和matplotlib中文字体显示(针对windows系统,,使用ipython notebook)
- Python 3下使用Matplotlib工具画图,中文显示乱码的问题解决(修改配置文件)
- matplotlib 中文字体问题