使用turtle模块绘制词频统计结果,其中词频数据
wordFrequency=
{"the":104,"a":63,"to":42,"of":42,"Kevin":36,"he":32,"you":28,"and":28,"is":27,"i":26}
以柱状图的形式展示统计结果。
python,turtle模块
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答 默认 最新
关注 如下所示,主要在遍历字典时要凑好坐标位置有点麻烦:
import turtle t = turtle.Pen() t.color("red") t.pensize(3) t.speed(0) wordFrequency = {"the":104,"a":63,"to":42,"of":42,"Kevin":36,"he":32,"you":28,"and":28,"is":27,"i":26} def Goto(x,y): t.penup() t.goto(x,y) t.pendown() def rect(x,y,h,w=45): Goto(x,y) for i in range(2): t.forward(w) t.left(90) t.forward(h) t.left(90) t.fillcolor('red') start_x , start_y = -320, -200 Goto(start_x , start_y) t.forward(630) for i,d in enumerate(wordFrequency.items()): rect(start_x + i*65, start_y ,d[1]*4 ) tx = t.xcor() Goto(tx+(6-len(d[0]))*4, t.ycor()-25) t.write(d[0], font=('Arial',14,'normal')) Goto(tx + (8 if d[1]>100 else 12), t.ycor()+d[1]*4+30) t.write(d[1], font=('Arial',14,'normal')) t.hideturtle() t.done()
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 2无用
悬赏问题
- ¥20 wireshark抓不到vlan
- ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
- ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
- ¥15 stata安慰剂检验作图但是真实值不出现在图上
- ¥15 c程序不知道为什么得不到结果
- ¥40 复杂的限制性的商函数处理
- ¥15 程序不包含适用于入口点的静态Main方法
- ¥15 素材场景中光线烘焙后灯光失效
- ¥15 请教一下各位,为什么我这个没有实现模拟点击
- ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来