python matplotlib绘图

来源:互联网 发布:2010年总决赛数据 编辑:程序博客网 时间:2024/06/06 19:37
import matplotlib  import matplotlib.pyplot as plt import random# generate 2 dimension pointsd = 2xmax = 20num_points = 10points = [[random.randint(0,xmax) for i in xrange(d)] for j in xrange(num_points)]print pointsplt.figure(1)plt.subplot(211)for point in points[:num_points]:plt.scatter(point[0], point[1])# seed the dataset with a fixed number of nearest neighbours# within a given small "radius"num_neighbours = 2radius = 0.1for point in points[:num_points]:    for i in xrange(num_neighbours):        points.append([x+random.uniform(-radius,radius) for x in point])print pointsplt.subplot(212)for point in points:plt.scatter(point[0], point[1])plt.show()

原创粉丝点击