定义初始点和随机点
import matplotlib
.pyplot
as plt
import numpy
as np
colors
= ['r','g','b']
x0
= (0,0)
x1
= (10, 0)
x2
= (5, np
.sqrt
(75))
z
= (3,4)
开始迭代
%matplotlib inline
fig
= plt
.figure
()
ax1
= fig
.add_subplot
(111)
ax1
.set_title
('triangle')
plt
.xlabel
('X')
plt
.ylabel
('Y')
plt
.ion
()
plt
.scatter
(x0
[0], x0
[1], c
=colors
[0], marker
='o')
plt
.scatter
(x1
[0], x1
[1], c
=colors
[1], marker
='o')
plt
.scatter
(x2
[0], x2
[1], c
=colors
[2], marker
='o')
points
= [x0
, x1
, x2
]
import numpy
as np
from IPython
import display
for i
in range(600):
index
= np
.random
.choice
(3)
z
= ((z
[0]+points
[index
][0])/2, (z
[1]+points
[index
][1])/2)
display
.clear_output
(wait
=True)
points
.append
(z
)
colors
.append
(colors
[index
])
for point
, color
in zip(points
, colors
):
plt
.scatter
(point
[0], point
[1], c
=color
, marker
='o')
plt
.pause
(0.00000001)
plt
.draw
()
转载请注明原文地址: https://mac.8miu.com/read-59064.html