matplotlib显示中文的方法

方法一:动态设置参数(推荐)

from matplotlib import pyplot as plt
plt.rcParams['font.sans-serif']=['SimHei']  # 用来正常显示中文标签
plt.rcParams['axes.unicode_minus'] = False  # 用来正常显示负号
# 更改了字体导致显示不出负号,因此将配署文件中axes.unicode minus : True修改为False。

方法二:设置字体

import matplotlib
font = {'family' : 'SimHei',
        'weight': 'bold',
        'size': 'larger'}
matplotlib.rc("font",**font)
# 以上代码等同于 matplotlib.rc("font",family='SimHei',weight="bold")

方法三:修改配置文件matplotlibrc

#font.family    : sans-serif
#font.sans-serif   : Bitstream Vera Sans, Lucida Grande, Verdana, Geneva, Lucid, Anal, Helvetica, Avant Ga

方法四:使用字体管理器

import matplotlib.pyplot as plt
from matplotlib.font_manager import FontProperties

# 指定系统字体
my_font = FontProperties(fname='C:/Windows/Fonts/SimHei.ttf', size=10)

plt.plot([10, 20], [20, 40])
plt.title('显示中文', fontproperties=my_font)
plt.show()
  • 1
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值