天天看点

解决jupyter中matplotlib中文乱码问题

第一步:系统中文字体查看

[hadoop@p168 ~]$ fc-list :lang=zh

#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()      

继续阅读