forked from jeffmiller00/PlayingWithPython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathch05_barchart.py
More file actions
43 lines (31 loc) · 972 Bytes
/
ch05_barchart.py
File metadata and controls
43 lines (31 loc) · 972 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env python3
# This program is for
# Author: MYGNU
# Please feel free to copy, distribute and modify till your heart is content
import turtle
def drawBar(t, height):
""" Get turtle t to draw one bar, of height. """
t.begin_fill() # start filling this shape
t.left(90)
t.forward(height)
t.write(' '+ str(height))
t.right(90)
t.forward(40)
t.right(90)
t.forward(height)
t.left(90)
t.end_fill() # stop filling this shape
xs = [48,117,200,240,160,260,220] # here is the data
maxheight = max(xs)
numbars = len(xs)
border = 10
tess = turtle.Turtle() # create tess and set some attributes
tess.color("blue")
tess.fillcolor("red")
tess.pensize(3)
wn = turtle.Screen() # Set up the window and its attributes
wn.bgcolor("lightgreen")
wn.setworldcoordinates(0-border,0-border,40*numbars+border,maxheight+border)
for a in xs:
drawBar(tess, a)
wn.exitonclick()