关于如何将这些数据作为条形图绘制在列表中的想法?
freqList = [0.09090909090909091, 0.0, 0.0, 0.09090909090909091, 0.18181818181818182, 0.0, 0.0, 0.0, 0.045454545454545456, 0.0, 0.0, 0.0, 0.0, 0.045454545454545456, 0.045454545454545456, 0.045454545454545456, 0.045454545454545456, 0.18181818181818182, 0.045454545454545456, 0.09090909090909091, 0.045454545454545456, 0.0, 0.045454545454545456, 0.0, 0.0, 0.0]
数字代表字母的出现:a-z
我需要x轴(a - z)上的字母值和y上的频率(0 - 1.00。
def letterFreqPlot(freqList):
t = turtle.Turtle()
screen = t.getscreen()
screen.setworldcoordinates(0,0,25,1.00)
t.goto(0,0)
答案 0 :(得分:0)
您应该遍历freqList
t.goto(0,0)
for item in freqList:
t.forward(1)
t.left(90)
t.forward(item)
t.left(90)
t.forward(1)
t.left(90)
t.forward(item)
t.left(90)
t.forward(1)
注意到通过嵌套另一个循环可以简化明显的重复
t.goto(0,0)
for item in freqList:
for dist in [1, item, 1, item]:
t.forward(dist)
t.left(90)
t.forward(1)