标签:style blog http ar color os sp for on
python34 中绘图基本是matplotlib库,基于matplotlib库可以绘制基本的图形。
1、基本绘图
(1)点图(data:http://pan.baidu.com/s/1i3L0UDB)
1 import matplotlib.pyplot as plt 2 import math 3 from numpy import * 4 def file2matrix(filename): 5 fr = open(filename) 6 numberOfLines = len(fr.readlines()) #get the number of lines in the file 7 returnMat = zeros((numberOfLines,3)) #prepare matrix to return 8 classLabelVector = [] #prepare labels return 9 fr = open(filename) 10 index = 0 11 for line in fr.readlines(): 12 line = line.strip() 13 listFromLine = line.split(‘\t‘) 14 returnMat[index,:] = listFromLine[0:3] 15 classLabelVector.append(int(listFromLine[-1])) 16 index += 1 17 return returnMat,classLabelVector 18 # return returnMat 19 20 21 22 datingDataMat,datingLabels = file2matrix(‘datingTestSet2.txt‘) 23 fig = plt.figure() 24 ax = fig.add_subplot(111) 25 ax.scatter(datingDataMat[:,1],datingDataMat[:,2],15.0*array(datingLabels),15.0*array(datingLabels)) 26 plt.show()
标签:style blog http ar color os sp for on
原文地址:http://www.cnblogs.com/andrew-elec90/p/4108224.html