【头歌平台实验】【使用Matplotlib模块进行数据可视化】【网络机器人相关法律责任】【网页抓取及信息提取】

使用Matplotlib模块进行数据可视化

第一关

python 复制代码
# 请编写代码绘制住宅商品房平均销售价格柱状图
import matplotlib
matplotlib.use("Agg")
#  请在此添加实现代码  #
# ********** Begin *********#
import matplotlib.pyplot as plt
from numpy import *
xstring = '2015 2014 2013 2012 2011     \
           2010 2009 2008 2007 2006     \
           2005 2004 2003 2002 2001    2000'
ystring = '12914 11826 12997 12306.41 12327.28 \
            11406 10608    8378 8667.02 8052.78 \
            6922.52    5744 4196 4336 4588    4751'
y = ystring.split()
y.reverse()
y = [float(e) for e in y]
xlabels = xstring.split()
xlabels.reverse()
x = range(len(xlabels))
plt.xticks(x, xlabels, rotation = 45)
plt.yticks(range(4000,13500,1000))
plt.ylim(4000,13500)
plt.bar(x, y, color = '#800080')
plt.savefig('picture/step1/fig1.png')
# ********** End **********#

第二关

python 复制代码
# 请编写代码绘制住宅商品房平均销售价格柱状图
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
import numpy as np
xstring = '2015 2014 2013 2012 2011     \
           2010 2009 2008 2007 2006     \
           2005 2004 2003 2002 2001    2000' #x轴标签
n = 6
ystring = ['']*n #y轴对应的6组数据
ystring[0] = '6793    6324    6237    5790.99    5357.1    5032    4681    3800    3863.9    3366.79    3167.66    2778    2359    2250    2170    2112'
ystring[1] = '6473    5933    5850    5429.93    4993.17    4725    4459    3576    3645.18    3119.25    2936.96    2608    2197    2092    2017    1948'
ystring[2] = '15157    12965    12591    11460.19    10993.92    10934    9662    7801    7471.25    6584.93    5833.95    5576    4145    4154    4348    4288'
ystring[3] = '12914    11826    12997    12306.41    12327.28    11406    10608    8378    8667.02    8052.78    6922.52    5744    4196    4336    4588    4751'
ystring[4] = '9566    9817    9777    9020.91    8488.21    7747    6871    5886    5773.83    5246.62    5021.75    3884    3675.14    3488.57    3273.53    3260.38'
ystring[5] = '4845    5177    4907    4305.73    4182.11    4099    3671    3219    3351.44    3131.31    2829.35    2235    2240.74    1918.83    2033.08    1864.37'
legend_labels = ['Commercial housing', 'Residential commercial housing',
          'high-end apartments', 'Office Building', 'Business housing', 'Others'] #图例标签
colors = ['#ff7f50', '#87cefa', '#DA70D6', '#32CD32', '#6495ED', '#FF69B4'] #指定颜色
#  请在此添加实现代码  #
# ********** Begin *********#
xlabels = xstring.split() # 年份切分
xlabels.reverse() # 年份序列倒序排列,从小到大
x = np.arange(1, n*len(xlabels), n) #x轴条形起始位置
w = 0.8 #条形宽度设置
for i in range(n):
    y = ystring[i].split()
    y.reverse()
    y = [float(e) for e in y] #将划分好的字符串转为float类型
    plt.bar(x+i*w, y, width = w, color = colors[i]) #以指定颜色绘制柱状图
plt.ylim([1450, 15300]) #指定y轴范围
plt.yticks(range(2000,15000,2000)) #指定y轴刻度
plt.xlim([-1,98])
plt.xticks(x+w*2.5, xlabels, rotation = 45) #添加x轴标签,旋转40度
plt.legend(legend_labels, loc = 'upper left') #添加图例,位置为左上角
plt.title('Selling Prices of Six Types of Housing')
plt.savefig('picture/step2/fig2.png') #存储图像
# ********** End **********#

第三关

python 复制代码
# 请绘制育龄妇女的受教育程度分布饼图
import matplotlib
matplotlib.use("Agg")
#  请在此添加实现代码  #
# ********** Begin *********#
import matplotlib.pyplot as plt
labels = ['none', 'primary', 'junior', 'senior', 'specialties', 'bachelor', 'master'] # 标签
colors = ['red','orange','yellow','green','purple','blue','black'] #指定楔形颜色
womenCount = [2052380, 11315444, 20435242, 7456627, 3014264, 1972395, 185028]
explode = [0,0,0.1,0,0,0,0] # 确定突出部分
plt.pie(womenCount, explode=explode, labels=labels, shadow=True,colors=colors)
plt.axis('equal')  # 用于显示为一个长宽相等的饼图
plt.savefig('picture/step3/fig3.png')
# ********** End **********#

第四关

python 复制代码
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
import numpy as np
labels = ['none', 'primary', 'junior', 'senior', 'specialties', 'bachelor', 'master'] # 标签
womenCount = [2052380, 11315444, 20435242, 7456627, 3014264, 1972395, 185028]
birthMen = [2795259, 12698141, 13982478, 2887164, 903910, 432333, 35915]
birthWomen = [2417485, 11000637, 11897674, 2493829, 786862, 385718, 32270]
liveMen = [2717613, 12477914, 13847346, 2863706, 897607, 429809, 35704]
liveWomen = [2362007, 10854232, 11815939, 2480362, 783225, 384158, 32136]
#  请在此添加实现代码  #
# ********** Begin *********#
x = np.arange(len(labels))
birth = np.array(birthMen) + np.array(birthWomen)
live = np.array(liveMen) + np.array(liveWomen)
plt.figure(figsize=[14,5]) #设置画布大小
plt.subplot(121)
birthrate = (1.0*live) / (1.0*np.array(womenCount))
plt.plot(x, birthrate, 'r')
plt.xticks(x, labels)
plt.subplot(122)
liverate = (1.0*live) / (1.0*birth) * 100
plt.plot(x, liverate, 'b')
plt.xticks(x, labels)
plt.savefig('picture/step4/fig4.png')
# ********** End **********#

网络机器人相关法律责任

第一关

python 复制代码
from urllib import request
import sys

def Evidence(url):
    try:
        response = request.urlopen(url)
        status_code = response.getcode()
        print(f"Status: {status_code} OK ")
    except Exception as e:
        print(e)

第二关

python 复制代码
import requests

def Evidence(url):
    try:
        response = requests.get(url)
        if response.status_code == 200:
            print("Status: 200")
        else:
            print(f"Status: {response.status_code}")
    except requests.RequestException as e:
        print("url请求失败")

第三关

python 复制代码
import re

def Evidence(text):
    # 定义匹配Email地址的正则表达式
    email_pattern = r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$'
    
    # 使用re.match进行匹配
    match = re.match(email_pattern, text)
    
    # 输出匹配结果,如果匹配不到输出None
    if match:
        print(match)
    else:
        print(None)

后面三关

后面三关域名过期做不了

网页抓取及信息提取

域名过期做不了

相关推荐
q567315231 小时前
从头开始的可视化数据 matplotlib:初学者努力绘制数据图
开发语言·python·php·pyqt·matplotlib
云卓科技1 小时前
无人机之巡航控制篇
科技·安全·机器人·无人机·制造
锦瑟居士3 小时前
交叉编译--目标平台aarch64 ubuntu 22.04
linux·运维·ubuntu·机器人
四川合睿达自动化控制工程有限公司8 小时前
隧道安全监测自动化系统解决方案
运维·物联网·安全·信息可视化·自动化
残诗9 小时前
全金属的两足机器人钢铁侠开发
机器人
视觉小萌新10 小时前
HIKROBOT_SDK_text1——机器人控制权
人工智能·机器人
极客小张10 小时前
基于STM32的工厂安防巡检机器人设计流程实现自主识别检测、机器人自主行驶、环境监控和数据采集
c语言·stm32·单片机·opencv·物联网·机器人·视觉检测
ZPC821010 小时前
URDF统一机器人建模语言
python·机器人
RPA中国10 小时前
基于RPA+AI的网页自动填写机器人 | OPENAIGC开发者大赛高校组优秀作品
人工智能·机器人·rpa