python matplotlib繪圖

import matplotlib  
import matplotlib.pyplot as plt 
import random

# generate 2 dimension points
d = 2
xmax = 20
num_points = 10
points = [[random.randint(0,xmax) for i in xrange(d)] for j in xrange(num_points)]
print points
plt.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 = 2

radius = 0.1
for point in points[:num_points]:
    for i in xrange(num_neighbours):
        points.append([x+random.uniform(-radius,radius) for x in point])
print points
plt.subplot(212)
for point in points:
	plt.scatter(point[0], point[1])
plt.show()

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章