失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > Python:WIN10解决matplotlib画图中显示中文宋体英文TimesNewRoman问题

Python:WIN10解决matplotlib画图中显示中文宋体英文TimesNewRoman问题

时间:2021-01-26 09:06:12

相关推荐

Python:WIN10解决matplotlib画图中显示中文宋体英文TimesNewRoman问题

1.tff字体下载:

simsun.tff

(或者直接百度’simsun.tff下载’,不建议直接复制C:\Windows\Fonts里的字体文件,易出问题)

2.删除缓冲目录

C:\Users\Administrator\.matplotlib

3.放置tff文件

找到Anaconda环境下的对应虚拟环境matplotlib目录,放置下载的simsun.tff文件。

D:\Program Files (x86)\Anaconda3\envs\jupyter\Lib\site-packages\matplotlib\mpl-data\fonts\ttf

4.修改matplotlibrc文件

找到D:\Program Files (x86)\Anaconda3\envs\jupyter\Lib\site-packages\matplotlib\mpl-data下matplotlibrc文件

font.family: sans-serif去掉前面的#号

font.sans-serif : simsun, Bitstream Vera Sans, Lucida Grande, Verdana, Geneva, Lucid, Arial, Helvetica, Avant Garde, sans-serif去掉前面的#,并在冒号后面添加simsun

axes.unicode_minus : False去掉前面的#,并将True改为False

5.中文宋体,英文新罗马

(注: 4中修改的为 sans-serif,后期我重新修改为serif,并在font.serif中重新添加了Times New Roman和simsun,没有Times New Roman.tff的同理百度下载添加timenewroman.tff)

全局设置Times New Roman

plt.rcParams['font.serif']=['Times New Roman']

局部设置中文宋体

plt.xticks(x, ('飞机', '自行车', '鸟'),fontfamily="simsun")

6.重启pycharm,画图成功

如果觉得《Python:WIN10解决matplotlib画图中显示中文宋体英文TimesNewRoman问题》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。