第一步:系统中文字体查看
[hadoop@p168 ~]$ fc-list :lang=zh
/System/Library/Fonts/STHeiti Medium.ttc: 黑体\-简,黑體\-簡,Heiti SC,黒体\-簡,Heiti\-간체:style=中等,中黑,Medium,Halbfett,Normaali,Moyen,Medio,ミディアム,중간체,Médio,Средний,Normal,Media
/System/Library/Fonts/PingFang.ttc: 苹方\-繁,蘋方\-繁,PingFang TC:style=常规体,標準體,Regular
/System/Library/Fonts/PingFang.ttc: 苹方\-简,蘋方\-簡,PingFang SC:style=常规体,標準體,Regular
/System/Library/Fonts/PingFang.ttc: 苹方\-港,蘋方\-港,PingFang HK:style=常规体,標準體,Regular
/System/Library/Fonts/STHeiti Light.ttc: 黑体\-繁,黑體\-繁,Heiti TC,黒体\-繁,Heiti\-번체:style=细体,細體,Mager,Fein,Light,Ohut,Fin,Leggero,ライト,가는체,Licht,Tynn,Leve,Светлый,Fina
/System/Library/Fonts/PingFang.ttc: .苹方\-简,.蘋方\-簡,.PingFang SC:style=中黑体,中黑體,Medium
/System/Library/Fonts/PingFang.ttc: .苹方\-港,.蘋方\-港,.PingFang HK:style=中黑体,中黑體,Medium
/System/Library/Fonts/PingFang.ttc: .苹方\-简,.蘋方\-簡,.PingFang SC:style=中粗体,中粗體,Semibold
/System/Library/Fonts/PingFang.ttc: .苹方\-港,.蘋方\-港,.PingFang HK:style=中粗体,中粗體,Semibold
/System/Library/Fonts/PingFang.ttc: .苹方\-繁,.蘋方\-繁,.PingFang TC:style=中黑体,中黑體,Medium
/System/Library/Fonts/PingFang.ttc: .苹方\-繁,.蘋方\-繁,.PingFang TC:style=常规体,標準體,Regular
/System/Library/Fonts/PingFang.ttc: .苹方\-繁,.蘋方\-繁,.PingFang TC:style=中粗体,中粗體,Semibold
/System/Library/Fonts/PingFang.ttc: .苹方\-简,.蘋方\-簡,.PingFang SC:style=常规体,標準體,Regular
/System/Library/Fonts/PingFang.ttc: .苹方\-港,.蘋方\-港,.PingFang HK:style=常规体,標準體,Regular
/System/Library/Fonts/PingFang.ttc: 苹方\-繁,蘋方\-繁,PingFang TC:style=极细体,極細體,Ultralight
第二步:在代码中指定字体配
#coding:utf-8
import matplotlib
from matplotlib.font_manager import *
import matplotlib.pyplot as plt
myfont = FontProperties(fname='/System/Library/Fonts/PingFang.ttc')
matplotlib.rcParams['axes.unicode_minus']=False
plt.plot([-1,2,-5,3])
plt.title(u'中文',fontproperties=myfont)
plt.legend((u'头等舱', u'2等舱',u'3等舱'),loc='best',prop=myfont) # sets our legend for our graph.
plt.show()