zoukankan      html  css  js  c++  java
  • 使用Python的turtle模块画出简单的柱状图

    代码如下:

    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()

    效果如下:

  • 相关阅读:
    QComboBox实现复选功能
    STL容器介绍
    QTableWidget控件总结
    (转)QT常用快捷键
    Hibernate的CRUD
    理解O/R Mapping
    JQuery验证input
    MapReduce概念(转)
    RedHat9上安装jdk
    集合框架
  • 原文地址:https://www.cnblogs.com/ncuhwxiong/p/6606732.html
Copyright © 2011-2022 走看看