【头歌平台实验】【使用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)

后面三关

后面三关域名过期做不了

网页抓取及信息提取

域名过期做不了

相关推荐
资源开发与学习1 天前
机器人运动规划源码解析
机器人
计算机编程小央姐2 天前
跟上大数据时代步伐:食物营养数据可视化分析系统技术前沿解析
大数据·hadoop·信息可视化·spark·django·课程设计·食物
CodeCraft Studio2 天前
【案例分享】TeeChart 助力 Softdrill 提升油气钻井数据可视化能力
信息可视化·数据可视化·teechart·油气钻井·石油勘探数据·测井数据
招风的黑耳2 天前
赋能高效设计:12套中后台管理信息系统通用原型框架
信息可视化·axure后台模板·原型模板
程思扬2 天前
利用JSONCrack与cpolar提升数据可视化及跨团队协作效率
网络·人工智能·经验分享·docker·信息可视化·容器·架构
路人与大师2 天前
【Mermaid.js】从入门到精通:完美处理节点中的空格、括号和特殊字符
开发语言·javascript·信息可视化
hi0_62 天前
机器学习实战(一): 什么是机器学习
人工智能·机器学习·机器人·机器学习实战
大视码垛机2 天前
速度与安全双突破:大视码垛机重构工业自动化新范式
大数据·数据库·人工智能·机器人·自动化·制造
WWZZ20253 天前
视觉SLAM第10讲:后端2(滑动窗口与位子图优化)
c++·人工智能·后端·算法·ubuntu·机器人·自动驾驶
deephub3 天前
机器人逆运动学进阶:李代数、矩阵指数与旋转流形计算
人工智能·机器学习·矩阵·机器人·李群李代数