legend()
关键就是在于这里:添加一个图例
plt.legend(loc='best')
调试图例的位置
在legend的参数中, loc参数设置图例的显示位置的:
plt.legend([l1, l2], ['first', 'second'], loc = 'upper right') #其中,loc表示位置的;
'best' : 0, (only implemented for axes legends)(自适应方式)
'upper right' : 1,
'upper left' : 2,
'lower left' : 3,
'lower right' : 4,
'right' : 5,
'center left' : 6,
'center right' : 7,
'lower center' : 8,
'upper center' : 9,
'center' : 10,
显示中文,中文的格式、显示负号
#coding:utf-8
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签
plt.rcParams['axes.unicode_minus']=False #用来正常显示负号
#有中文出现的情况,需要u'内容'
labels = u'男性好友', u'女性好友', u'未填性别'
下面是Windows的字体对应名称,Follow your heart, 各种换!
黑体 SimHei
微软雅黑 Microsoft YaHei
微软正黑体 Microsoft JhengHei
新宋体 NSimSun
新细明体 PMingLiU
细明体 MingLiU
标楷体 DFKai-SB
仿宋 FangSong
楷体 KaiTi
仿宋_GB2312 FangSong_GB2312
楷体_GB2312 KaiTi_GB2312
颜色,显示颜色
colors = ['red','yellowgreen','l