python matplotlib中文显示乱码解决
2016-02-26 15:48
1011 查看
问题描述:python matplotlib绘图中文显示乱码
问题根源:matplotlib的默认字体并非中文字体
解决:设置为中文字体
linux下查找中文字体:fc-list :lang=zh-cn #注意:前有个空格
windows下中文字体路径:c:\windows\fonts\simsun.ttc
方法1
方法2
实测:
- ubuntu 14.04 64bit + python2.7 64bit:方法1有效,方法2未测试
- win7 64bit + Anaconda 64bit(python 2.7) :方法1无效,方法2有效
参考来源:
python中matplotlib绘图中文显示问题
Ubuntu 12.04 查看自带的中文字体
Matplotlib输出中文显示问题
问题根源:matplotlib的默认字体并非中文字体
解决:设置为中文字体
linux下查找中文字体:fc-list :lang=zh-cn #注意:前有个空格
windows下中文字体路径:c:\windows\fonts\simsun.ttc
方法1
from matplotlib.font_manager import FontProperties font = FontProperties(fname = "/usr/share/fonts/truetype/arphic/ukai.ttc", size=14) plt.title(u"用户数量(Y)关于游戏消费金额(X)的分布图",fontproperties=font)
方法2
from pylab import mpl mpl.rcParams['font.sans-serif'] = ['FangSong'] # 指定默认字体 mpl.rcParams['axes.unicode_minus'] = False # 解决保存图像是负号'-'显示为方块的问题
实测:
- ubuntu 14.04 64bit + python2.7 64bit:方法1有效,方法2未测试
- win7 64bit + Anaconda 64bit(python 2.7) :方法1无效,方法2有效
参考来源:
python中matplotlib绘图中文显示问题
Ubuntu 12.04 查看自带的中文字体
Matplotlib输出中文显示问题
相关文章推荐
- Python动态类型的学习---引用的理解
- Python3写爬虫(四)多线程实现数据爬取
- 垃圾邮件过滤器 python简单实现
- 下载并遍历 names.txt 文件,输出长度最长的回文人名。
- install and upgrade scrapy
- Scrapy的架构介绍
- Centos6 编译安装Python
- 使用Python生成Excel格式的图片
- 让Python文件也可以当bat文件运行
- [Python]推算数独
- Python中zip()函数用法举例
- Python中map()函数浅析
- Python将excel导入到mysql中
- Python在CAM软件Genesis2000中的应用
- 使用Shiboken为C++和Qt库创建Python绑定
- FREEBASIC 编译可被python调用的dll函数示例
- Python 七步捉虫法