1 # encoding=utf-8 2 import matplotlib.pyplot as plt 3 from pylab import * #支持中文 4 mpl.rcParams['font.sans-serif'] = ['SimHei'] 5 6 names = ['5', '10', '15', '20', '25'] 7 x = range(len(names)) 8 y = [0.855, 0.84, 0.835, 0.815, 0.81] 9 y1=[0.86,0.85,0.853,0.849,0.83] 10 #plt.plot(x, y, 'ro-') 11 #plt.plot(x, y1, 'bo-') 12 #pl.xlim(-1, 11) # 限定横轴的范围 13 #pl.ylim(-1, 110) # 限定纵轴的范围 14 plt.plot(x, y, marker='o', mec='r', mfc='w',label=u'y=x^2曲线图') 15 plt.plot(x, y1, marker='*', ms=10,label=u'y=x^3曲线图') 16 plt.legend() # 让图例生效 17 plt.xticks(x, names, rotation=45) 18 plt.margins(0) 19 plt.subplots_adjust(bottom=0.15) 20 plt.xlabel(u"time(s)邻居") #X轴标签 21 plt.ylabel("RMSE") #Y轴标签 22 plt.title("A simple plot") #标题 23 24 plt.show()