字体库
当制作一张图时,x轴、y轴和图名一般都要赋予名称,方便理解,乱码显示十分不易于理解。在mac上字体库一般保存在以下两个文件中,随意选择一个就可以。
/Library/Fonts/Songti.ttc
/System/Library/Fonts/PingFang.ttc
引入文件
下方代码实现的机器学习中的k-近邻算法,分析数据时使用matplotlib绘制散点图。
import matplotlib as mpl
import matplotlib.pyplot as plt
font = mpl.font_manager.FontProperties(fname='/System/Library/Fonts/PingFang.ttc')
plt.suptitle(u'散点图', fontsize=18,fontproperties = font)
plt.xlabel(u'玩视频游戏所消耗的时间百分比',fontproperties = font)
plt.ylabel(u'每周消费的冰淇淋公升数',fontproperties = font)
plt.show()