本身mac下载过sublime text3后,自身是显示中文的,不会出现输入中文就出现乱码的现象。即使没有出现设置显示中文,设置中文后,在生成图像时会出现小方框(并没有很长的一段乱码)。
在导入时输出from matplotlib.font_manager import FontProperties
设置font=FontProperties(fname=’/System/Library/Fonts/STHeiti Light.ttc’, size=16)
在需要显示中文的属性时,输入fontproperties=font。
例如:plt.title(" 数据",fontproperties=font)
import matplotlib.pyplot as plt
from matplotlib.font_manager import FontProperties
font = FontProperties(fname=’/System/Library/Fonts/STHeiti Light.ttc’, size=16)
plt.title(“中文标题”, fontproperties=font)
plt.show()