turtle绘的正态分布图.py

0 Comments

李兴球Python之turtle normal distribute正态分布图

“””
turtle绘的正态分布图.py
“””
import turtle
import numpy as np

datas = [int(np.random.randn()*100) for _ in range(50000)]

print(min(datas))
print(max(datas))
counts = {}
for c in range(min(datas),max(datas)+1):
freq = datas.count(c) # 每个数产生的次数
counts[c] = freq # 放在字典中,如counts[3]=50,记录了3有50个

turtle.delay(0)
turtle.speed(0)
turtle.penup()
for key,value in counts.items():
turtle.goto(key,value)
turtle.dot(4)

turtle.done()

发表评论