本文實例為大家分享了python畫折線圖的具體代碼,供大家參考,具體內容如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# encoding=utf-8 import matplotlib.pyplot as plt from pylab import * #支持中文 mpl.rcParams[ 'font.sans-serif' ] = [ 'SimHei' ] names = [ '5' , '10' , '15' , '20' , '25' ] x = range ( len (names)) y = [ 0.855 , 0.84 , 0.835 , 0.815 , 0.81 ] y1 = [ 0.86 , 0.85 , 0.853 , 0.849 , 0.83 ] #plt.plot(x, y, 'ro-') #plt.plot(x, y1, 'bo-') #pl.xlim(-1, 11) # 限定橫軸的范圍 #pl.ylim(-1, 110) # 限定縱軸的范圍 plt.plot(x, y, marker = 'o' , mec = 'r' , mfc = 'w' ,label = u 'y=x^2曲線圖' ) plt.plot(x, y1, marker = '*' , ms = 10 ,label = u 'y=x^3曲線圖' ) plt.legend() # 讓圖例生效 plt.xticks(x, names, rotation = 45 ) plt.margins( 0 ) plt.subplots_adjust(bottom = 0.15 ) plt.xlabel(u "time(s)鄰居" ) #X軸標簽 plt.ylabel( "RMSE" ) #Y軸標簽 plt.title( "A simple plot" ) #標題 plt.show() |
效果圖:
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。
原文鏈接:http://www.cnblogs.com/altlb/p/7160191.html