Windows-Python-matplotlib-中文字体显示

前言:

在windows上捣鼓python,用matplotlib画一些图,出现中文字体无法显示问题,找找资料,解决并记录下来
原文链接

Linux

  • 下载中文字体(黑体,看准系统版本)

  • 下载 arial unicode ms 字体到 /home 目录

  • 拷贝字体到 usr/share/fonts 下:

sudo cp ~/arial\ unicode\ ms.ttf /usr/share/fonts/arial\ unicode\ ms.ttf
  • 修改配置文件matplotlibrc 并且在~/.matplotlib/matplotlibrc也进行修改
  • 在安装的地方找到虚拟环境ai/lib/python3.6/site-packages/matplotlib/mpl-data目录下面,修改下面配置
font.family         : sans-serif        

font.sans-serif     : arial unicode ms, Bitstream Vera Sans, Lucida Grande, Verdana, Geneva, Lucid, Arial, Helvetica, Avant Garde, sans-serif
  • 删除matplotlib字体缓存:
rm -rf ~/matplotlib/fontList.json

Windows

全局设置


# 设置matplotlib正常显示中文和负号
matplotlib.rcParams['font.sans-serif']=['SimHei']   # 用黑体显示中文
matplotlib.rcParams['axes.unicode_minus']=False     # 正常显示负号

局部设置

from matplotlib.font_manager import FontProperties


font1 = FontProperties(fname=r"c:\windows\fonts\simsun.ttc")
font2 = FontProperties(fname=r"c:\windows\fonts\STHUPO.TTF")
font3 = FontProperties(fname=r"c:\windows\fonts\STCAIYUN.TTF")
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值