使用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()
效果如下:

使用Python的turtle模块画出简单的柱状图的更多相关文章
- 使用Python的turtle模块画出最简单的五角星
代码如下: import turtle def main(): t = turtle.Turtle() t.hideturtle() lengthOfSize = 200 drawFivePointS ...
- Python——用turtle模块画海龟的第一步
*/ * Copyright (c) 2016,烟台大学计算机与控制工程学院 * All rights reserved. * 文件名:text.cpp * 作者:常轩 * 微信公众号:Worldhe ...
- python的turtle模块画折线图
代码如下: import turtle yValues = [10.0,7.4,6.4,5.3,4.4,3.7,2.6] def main(): t = turtle.Turtle() t.hidet ...
- python中turtle模块画正多边形
画正多边形主要是计算多边形每个角度对应的外角的度数,计算出来这个度数即可画图,相对来说非常简单 以正六边形为例 import turtle import time t = turtle.Pen() f ...
- 课程作业——Python基础之使用turtle库画出红旗
代码如下: import turtle # 设置画笔和背景颜色 turtle.color('yellow') turtle.bgcolor('red') # 通过偏移量和尺寸大小画星星 def dra ...
- 一篇文教你使用python Turtle库画出“精美碎花小清新风格树”快来拿代码!
Turtle库手册可以查询查询 python图形绘制库turtle中文开发文档及示例大全,手册中现有示例,不需要自己动手就可以查看演示. 使用Turtle画树,看了一下网上的代码,基本上核心的方法是使 ...
- python中logging模块的一些简单用法
用Python写代码的时候,在想看的地方写个print xx 就能在控制台上显示打印信息,这样子就能知道它是什么了,但是当我需要看大量的地方或者在一个文件中查看的时候,这时候print就不大方便了,所 ...
- centos下python的pymssql模块安装及简单使用
1.安装pymssq模块 1-1.环境准备: 1-1-1.unixODBC安装 yum install unixODBC unixODBC-devel -y 1-1-2.freetds安装 下载 fr ...
- python 利用tkinter模块设计出window窗口(搞笑版)
代码如下 from tkinter import * import tkinter from tkinter import messagebox #定义了一个函数,当关闭window窗口时将会弹出一个 ...
随机推荐
- IDEA2017 使用(二)
1.鼠标悬浮在方法上显示api 2.关闭拼写检查 3.自动导入包(存在多个包时需要手动导入) 4.设置方法线
- c++ fstream用法
今天介绍一个复制 粘贴的函数,用fstream实现 #include "stdafx.h" #include<iostream> #include<fstream ...
- LOJ tangjz的背包
题目大意 有 \(n\) 个物品, 第 \(i\) 个物品的体积为 \(i\) 令 \(f(x)\) 为 选择 \(m\) 个物品, 体积和为 \(x\) 的方案数 令 \(V = \sum_{i=1 ...
- Flume的安装,配置及使用
1,上传jar包 2,解压 3,改名 4,更改配置文件 将template文件重镜像 root@Ubuntu-1:/usr/local/apache-flume/conf# cat flume-env ...
- 【uva10829-求形如UVU的串的个数】后缀数组+rmq or 直接for水过
题意:UVU形式的串的个数,V的长度规定,U要一样,位置不同即为不同字串 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&am ...
- Runtime类 调用windows程序。
import java.io.*; public class webcyz { /** * @param args */ public static void main(String[] args) ...
- python基础===pip安装模块失败
此情况只用于网络不畅的安装模块背景: 总出现红色的 Could not find a version that satisfies the requirement pymongo(from versi ...
- Linux中生成Core Dump系统异常信息记录文件的教程
Linux中生成Core Dump系统异常信息记录文件的教程 http://www.jb51.net/LINUXjishu/473351.html
- css3 不常用但重要的属性
IOS 2.-webkit-touch-callout (ios 2.0+) none:禁止弹出系统弹窗 default:默认 Android Common 1.-webkit-user-select ...
- go语言的定时器
package main import ( "fmt" "time" ) func main(){ //创建一个定时器,时间为2s,2s过后会自动往通道里面写入 ...