Python
(파이썬) 터틀그래픽: 막대 그래프 (차트) 그리기
고니자니
2023. 8. 19. 22:16
반응형
파이썬의 터틀 그래픽으로 막대그래프를 그리는 코드입니다.
import turtle
def drawBar(height):
t.begin_fill()
t.left(90)
t.forward(height)
t.write(str(height), font = ('Times New Roman', 16, 'bold'))
t.right(90)
t.forward(40)
t.right(90)
t.forward(height)
t.left(90)
t.end_fill()
data = [120, 60, 200, 30, 150]
cc = ["blue","red","magenta","yellow","green"]
t = turtle.Turtle()
t.color("black")
t.pensize(3)
for i in range(5):
t.fillcolor(cc[i])
drawBar(data[i])
반응형