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

news/2024/10/18 14:59:35/

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

第一关

# 请编写代码绘制住宅商品房平均销售价格柱状图
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 **********#

第二关

# 请编写代码绘制住宅商品房平均销售价格柱状图
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 **********#

第三关

# 请绘制育龄妇女的受教育程度分布饼图
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 **********#

第四关

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 **********#

网络机器人相关法律责任

第一关

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

第二关

import requestsdef 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请求失败")

第三关

import redef 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)# 输出匹配结果,如果匹配不到输出Noneif match:print(match)else:print(None)

后面三关

后面三关域名过期做不了

网页抓取及信息提取

域名过期做不了


http://www.ppmy.cn/news/1540024.html

相关文章

JavaScript 小技巧和诀窍:助你写出更简洁高效的代码

JavaScript 是一门灵活且强大的语言,但精通它并非易事。以下 30 个 JavaScript 小技巧和诀窍,可以帮助每位开发者写出更简洁高效的代码,并提升开发流程。 1. 使用 let 和 const 替代 var 避免使用 var 声明变量。使用 let 和 const 来确保块…

STM32CubeIDE使用ADC采用DMA重大BUG

问题描述 STM32CubeIDE 1.8.0问题 大牛攻城狮最近调试STM32L151CBT6。由于项目上使用该款芯片做控制电源使用,其中涉及到多路ADC的数据采样。使用STM32CubeIDE 1.8.0版本详细如下图所示 这里大概率是STM32CubeMX版本太低了,从图上看才是6.4.0 注意这里…

kafka消息丢失?可能和seekToEnd有关

最近遇到kafka消息丢失的偶现问题,排查许久都没找到原因。后面通读代码,才发现消息丢失和seekToEnd有关。 我有一套环境是HA架构,3个节点,每个节点有多个app,每个app启动时会向zk注册,然后利用zk选出主app&…

操作系统简介:作业管理

作业管理 一、作业管理1.1 作业控制1.2 作业的状态及其转换1.3 作业控制块和作业后备队列 二、作业调度2.1 调度算法的选择2.2 作业调度算法2.3 作业调度算法性能的衡量指标 三、人机界面 作业:系统为完成一个用户的计算任务(或一次事务处理)…

Python打包之嵌入式打包神器PyStand

在使用Python开发项目时,如果项目依赖了如torch这样的大型第三方库,打包后的体积可能会变得非常庞大(超过1GB)。传统的打包工具,如Nuitka或PyInstaller,可能会面临打包成功率低、耗时长、打包后体积巨大的问…

4.stable-diffusion-webui1.10.0--图像修复(adetailer)插件

ADetailer是Stable Diffusion WebUI的一个插件,它通过深度学习模型智能检测图像中的人脸、手部及身体等关键部位,并自动进行重绘修复,使得生成的图像更加自然、符合预期。 ADetailer插件主要应用于图像的细节增强、降噪和修复,特…

hive自定义函数缺包报错,以及运行时与hive冲突解决

一.问题描述 仅描述了从配置到打包上传的过程&#xff0c;想要看解决请直接跳到下文的对应模块。 在使用hive设置自定义函数的时候在pom.xml中配置如下依赖&#xff0c;使其打包的时候带依赖打包&#xff1a; <dependencies><dependency><groupId>org.apa…

递归——二叉树中的深搜

文章目录 计算布尔二叉树的值求根节点到叶节点数字之和二叉树剪枝验证二叉搜索树二叉搜索树中第 K 小的元素二叉树的所有路径 二叉树中的深搜有三种方法 前序遍历 根->左子树->右子树 中序遍历 左子树->根->右子树 前序遍历 左子树->右子树->根 计算布尔…