首页 > 编程语言 > 详细

使用Python的turtle模块画出简单的柱状图

时间:2017-03-23 20:36:08      阅读:459      评论:0      收藏:0      [点我收藏+]

代码如下:

import turtle
heights = [856, 420,360,260,205]
def main():
    t = turtle.Turtle()
    t.hideturtle()
    for i in range(5):
        drawFilledRectangle(t,-200+(76*i),0,76,heights[i]/4,"black","light blue")
    displayText(t)
def drawFilledRectangle(t,x,y,w,h,colorP="black",colorF="white"):
    t.pencolor(colorP)
    t.fillcolor(colorF)
    t.up()
    t.goto(x,y)
    t.down()
    t.begin_fill()
    t.goto(x+w,y)
    t.goto(x+w,y+h)
    t.goto(x,y+h)
    t.goto(x,y)
    t.end_fill()
def displayText(t):
    languages = ["haha1", "haha2", "haha3", "haha4", "haha5"]
    t.pencolor("blue")
    t.up()
    for i in range(5):
        t.goto((-162+76*i),heights[i] / 4)
        t.write(str(heights[i]),align="center",font=("Arial",10,"normal"))
        t.goto((-162+76*i),10)
        t.write(languages[i],align="center",font=("Arial",10,"normal"))
        t.goto(-200,-25)
        t.write("haha 统计图",font=("Arial",10,"normal"))
        t.goto(-200,-45)
        t.write((哈哈哈哈哈啊哈哈),font=("Arial",10,"normal"))
main()

效果如下:

技术分享

 

使用Python的turtle模块画出简单的柱状图

原文:http://www.cnblogs.com/ncuhwxiong/p/6606732.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!