python汉字字体宋体_设置matplotlib中文显示(宋体)

更新时间:2023-06-07 08:31:09 阅读: 评论:0

python汉字字体宋体_设置matplotlib中⽂显⽰(宋体)去油污小窍门
记录设置 matplotlib中⽂显⽰,免得下次就忘了
环境:win7 64, Anaconda,Python3.5.2,matplotlib1.5.3最近折腾了⼀会⼉iPython,想学学⽤matplotlib作图,遂安装了Anaconda。不料matplotlib对中⽂⽀持不好,默认情况下没有中⽂字体,打出来⼀堆□□。咋解决呢?baidu,Google⼀起上呗,结果并不能让⼈满意,不过还是学到基本设置都在MATPLOTLIBRC⽂件中。
晋楚城濮之战
MATPLOTLIBRC位置:INSTALL\Lib\site-packages\matplotlib\mpl-data\其中### FONT部分包括以下设置,其中rif, sans-rif, cursive, fantasy, monospace是matplotlib的五种font.family
#font.rif : simsun, ...
#font.sans-rif :simhei, ...
#font.cursive : ...
#font.fantasy : ...
#space : ...
将simsun(宋体),simhei(⿊体)添加到对应的rif和sans-rif⾥⾯,保存。
此时可以正确显⽰中⽂⿊体,但是宋体仍然不⾏。
再打开INSTALL\Lib\site-packages\matplotlib\font_manager.py 进⾏编辑
在⼤约155-162⾏,如下,
def get_fontext_synonyms(fontext):
"""
Return a list of file extensions extensions that are synonyms for
the given file extension *fileext*.
好看的电影排行榜
"""
return {'ttf': ('ttf', 'otf'),
'otf': ('ttf', 'otf'),
春羽图片
'afm': ('afm',)}[fontext]
这部分⽤来识别字体的扩展名,由于simsun等某些中⽂字体扩展名是ttc,所以没办法被matplotlib识别加载,将部分略作修改后保存即可。
什么是素质教育return {'ttf': ('ttf', 'otf'), ...修改为
return {'ttf': ('ttf', 'otf', 'ttc'), ...另外可能有必要清理掉系统盘中Urs\YOURNAME\.matplotlib\下的缓存⽂件fontList.py3k.cache
移动止损
然后打开
ipython --pylab
import matplotlib.pyplot as plt
rc('font',**{'family':'sans-rif','sans-rif':['simsun']})
plt.title(u'中⽂')
<(.2,.8,u'这也是中⽂',fontsize=40)
中国移动流量查询
可正常显⽰中⽂
其他windows所⽤字体在系统的Windows\Fonts\注意:只测试了⿊体和宋体,并未测试其他字体。
项羽王者荣耀

本文发布于:2023-06-07 08:31:09,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/82/892401.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:字体   设置   部分   安装   作图
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图