解决seaborn和matplotlib中中文字体显示方框的问题

1、下载字体:


2、人工指定字体:

import numpy as np

import pylab as pl

import matplotlib.font_manager as fm

fonts = fm.FontProperties(fname='../fonts/msyh.ttc') # 设置字体

t = np.arange(0.0,2.0 * np.pi,0.01) # 自变量取值范围

s = np.sin(t) # 计算正弦函数值

z = np.cos(t) # 计算余弦函数值

pl.plot(t,s,label='正弦')

pl.plot(t,z,label='余弦')

pl.xlabel('x-变量',fontproperties=fonts ,fontsize=24) #设置标签

pl.ylabel('y-正弦余弦函数值',fontproperties=fonts ,fontsize=24)

pl.title('sin-cos函数图像',fontproperties=fonts ,fontsize=32) #图像标题

pl.legend(prop=fonts )

pl.show()

3、实际应用:

解决seaborn和matplotlib中中文字体显示方框的问题_第1张图片

解决seaborn和matplotlib中中文字体显示方框的问题_第2张图片




你可能感兴趣的:(python)