Python海龟数据分析,第七次全国人口普查历年数据图表.py

Python第七次全国人口普查历年数据图表

"""
   Python海龟数据分析,第七次全国人口普查历年数据图表.py
   使用Python的海龟模块能进行数据分析,显示统计图标,画柱状图吗?
   答案是肯定的。下面的程序主要使用了变形shapesize和图章功能。
   把每一年人口数据以柱状图的形式显示出来。
   本程序网址:  http://www.lixingqiu.com/2021/05/12/python%e6%b5%b7%e9%be%9f%e6%95%b0%e6%8d%ae%e5%88%86%e6%9e%90%ef%bc%8c%e7%ac%ac%e4%b8%83%e6%ac%a1%e5%85%a8%e5%9b%bd%e4%ba%ba%e5%8f%a3%e6%99%ae%e6%9f%a5%e5%8e%86%e5%b9%b4%e6%95%b0%e6%8d%ae%e5%9b%be/
   
   更多用turtle模块, pygame模块创造的创意程序,请上萍乡李兴球博客 www.lixingqiu.com
"""
import turtle

years = [1953,1964,1982,1990,2000,2010,2020]      # 年份表
datas = [6.01,7.23,10.31,11.60,12.95,13.70,14.43] # 数据含港澳台,单位:亿
cs = ['red','orange','yellow','blue','cyan','blue','purple'] # 颜色表

points =((0,0),(0,10),(-20,10),(-20,-10),(0,-10))
turtle.addshape('csquare',points)
turtle.shape('csquare')

turtle.bgcolor("pink")               # 背景色为粉红色
turtle.penup()                       # 抬起笔来

turtle.goto(-200,-150)               # 定位到此开始盖图章
turtle.hideturtle()

ft = ('',14,'normal')
for i in range(7):
    c = cs[i]
    year = years[i]
    人口数量 = datas[i]              # 使用中文更好理解
    turtle.color(c)
    turtle.shapesize(人口数量,1)     # 变形
    turtle.stamp()                   # 盖图章(柱状图)
    # 下面这4行代码是写年份,需要先调整y坐标
    turtle.color('blue')
    turtle.sety(turtle.ycor()-50)
    turtle.write(year,align='center',font=ft)
    turtle.sety(turtle.ycor()+50)
    # 下面这4行代码是写人口数量。
    turtle.color('black')
    turtle.sety(turtle.ycor()+人口数量*21)
    turtle.write(人口数量,align='center',font=ft)
    turtle.sety(turtle.ycor()-人口数量*21)    
    
    turtle.setx(turtle.xcor()+76)    # 海龟往右移76个单位

turtle.goto(0,240)
ft = ('',20,'underline italic')
s = '第七次全国人口普查历年数据图表'
turtle.write(s,align='center',font=ft)

turtle.goto(0,180)
ft = ('',12,'normal')
s = '单位:亿,(含港澳台)'
turtle.write(s,align='center',font=ft)

turtle.goto(0,-280)
ft = ('',12,'normal')
s = '程序编写:李兴球@2021/5/12,8:18分'
turtle.write(s,align='center',font=ft)

本程序已经记录在要人博客里,需要的联系本人!

李兴球Pythonxia二维码名片

 

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

李兴球

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值