method 1
Solve the Chinese garbled problem
plt.rcParams['font.family']='SimHei'
or
plt.rcParams['font.sans-serif']=['SimHei']
Method 2
Step 1: View system Chinese fonts
fc-list :lang=zh
Step 2: Specify the font configuration in the code
#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()
Method 3
https://blog.csdn.net/q1148013214/article/details/81172446