星辰大海路上的种花家 - 默认分类 只是一个默认分类 2024-11-16T03:33:00+00:00 Typecho /index.php/feed/atom/category/default/ <![CDATA[智慧城市建设中的交通数据分析与可视化python+Matplotlib]]> /index.php/posts/284.html 2024-11-16T03:33:00+00:00 2024-11-16T03:33:00+00:00 种花家 http://zy种花家.cn import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from reportlab.lib.pagesizes import letter
from reportlab.pdfgen import canvas

    1. 数据模拟生成 (1000条数据)*
      roads = ['A路', 'B路', 'C路', 'D路', 'E路']
      times = ['08:00-10:00', '17:00-19:00']
      dates = pd.date_range(start='2024-01-01', periods=30, freq='D') # 模拟30天的数据
  • 随机生成数据*
    data = []
    for date in dates:
    for time in times:

      for road in roads:
          num_vehicles = np.random.randint(100, 500)  # 车辆数目
          signal_cycle = np.random.randint(60, 120)  # 信号灯周期
          avg_speed = np.random.randint(30, 60)  # 平均车速
          accidents = np.random.randint(0, 3)  # 交通事故数量
          data.append([date, road, time, num_vehicles, signal_cycle, avg_speed, accidents])

    模拟了一个包含多个道路、多个时段、多个日期的交通数据集。
    roads、times 和 dates 定义了数据的维度,而每条记录表示在某个时间段、某个道路上的交通情况。
    num_vehicles、signal_cycle、avg_speed 和 accidents 分别模拟了该时段该路段的车辆数量、信号灯周期、平均车速和交通事故数。


  • 将数据转换为DataFrame*
    df = pd.DataFrame(data, columns=['日期', '道路', '时间段', '车辆数目', '信号灯周期', '平均车速', '交通事故数'])

    1. 数据清洗*
      df = df[df['车辆数目'] > 0]
      df = df[df['平均车速'] > 0]
      df = df[df['信号灯周期'] > 0]
      清洗数据的主要目的是移除无效记录,如 车辆数目、平均车速 或 信号灯周期 为零的情况,确保数据的有效性和合理性。

    1. 数据分析*
      df['交通事故率'] = df['交通事故数'] / df['车辆数目'] # 计算交通事故率

road_summary = df.groupby(['日期', '道路', '时间段']).agg({

'车辆数目': 'sum',
'平均车速': 'mean',
'交通事故数': 'sum',
'交通事故率': 'mean'

}).reset_index()
交通事故率:这里计算了每条记录的交通事故率,即 交通事故数 / 车辆数目,这一指标能有效反映事故的频发程度。
聚合数据:按日期、道路和时间段对数据进行分组,并对每个组别进行汇总:
sum:对 车辆数目 和 交通事故数 进行求和。
mean:对 平均车速 和 交通事故率 计算均值。
最终得到的 road_summary DataFrame 包含了按道路、时间段和日期汇总的车流量、车速、事故数等信息。


    1. 数据可视化*
  • 4.1 设置字体(避免中文显示问题)*
    plt.rcParams['font.sans-serif'] = ['SimHei'] # 设置支持中文的字体
    plt.rcParams['axes.unicode_minus'] = False # 解决负号显示问题
    通过设置 plt.rcParams,确保了生成的图表能够正确显示中文字符,同时避免了负号显示问题。

  • 4.2 城市主要道路的车流量热力图*
    plt.figure(figsize=(10, 6))
    heatmap_data = road_summary.pivot_table(index='道路', columns='时间段', values='车辆数目', aggfunc='sum')
    sns.heatmap(heatmap_data, annot=True, cmap='YlGnBu', fmt='d')
    plt.title('城市主要道路车流量热力图')
    plt.xlabel('时间段')
    plt.ylabel('道路')
    plt.tight_layout()
    plt.savefig('traffic_heatmap.png') # 保存为PNG文件
    plt.close()
    通过热力图 (heatmap) 展示不同道路和时间段的车流量。
    使用 pivot_table 来转化数据,index 是道路,columns 是时间段,values 是车辆数目。
    annot=True 表示在每个格子中显示具体数值,cmap='YlGnBu' 选择了颜色映射。

  • 4.3 交通高峰时段的车流量趋势图*
    plt.figure(figsize=(10, 6))
    high_traffic = road_summary.groupby(['时间段'])['车辆数目'].sum()
    high_traffic.plot(kind='line', marker='o', color='b')
    plt.title('交通高峰时段车流量趋势图')
    plt.xlabel('时间段')
    plt.ylabel('总车流量')
    plt.grid(True)
    plt.tight_layout()
    plt.savefig('traffic_peak_times.png') # 保存为PNG文件
    plt.close()
    绘制了交通高峰时段的车流量趋势图,以时间段为 X 轴,总车流量为 Y 轴。
    通过 groupby 汇总每个时间段的车流量,并绘制折线图。

  • 4.4 各道路的事故分布图*
    plt.figure(figsize=(10, 6))
    sns.barplot(data=road_summary, x='道路', y='交通事故数', hue='时间段')
    plt.title('各道路事故分布图')
    plt.xlabel('道路')
    plt.ylabel('交通事故数')
    plt.tight_layout()
    plt.savefig('traffic_accident_distribution.png') # 保存为PNG文件
    plt.close()
    使用 barplot 绘制每条道路在不同时间段的事故数分布。
    通过 hue='时间段' 参数,按时间段分不同颜色。

4.5 信号灯周期与车流量的关系曲线图
plt.figure(figsize=(10, 6))
sns.scatterplot(data=df, x='信号灯周期', y='车辆数目', hue='道路', style='时间段')
plt.title('信号灯周期与车流量之间的关系')
plt.xlabel('信号灯周期 (秒)')
plt.ylabel('车辆数目')
plt.legend(title='道路')
plt.tight_layout()
plt.savefig('signal_cycle_traffic_flow.png') # 保存为PNG文件
plt.close()
绘制了信号灯周期与车辆数目之间的散点图。
每个点代表一个记录,hue='道路' 按道路分色,style='时间段' 按时间段区分点的样式。


    1. 生成CSV文件*
      df.to_csv('traffic_data.csv', index=False, encoding='utf-8')
      将生成的数据保存为 CSV 文件,方便后续分析或存档。

    1. 生成PDF报告*
      def generate_pdf_report():
      c = canvas.Canvas("analysis_report.pdf", pagesize=letter)
      width, height = letter

      • 设置标题*
        c.setFont("Helvetica-Bold", 16)
        c.drawString(30, height - 40, "交通数据分析报告")
      • 添加数据分析过程*
        c.setFont("Helvetica", 12)
        c.drawString(30, height - 80, "1. 数据生成与清洗:")
        c.drawString(30, height - 100, " - 生成了包含交通流量、信号灯周期、车速和事故数等数据。")
        c.drawString(30, height - 120, " - 对异常值进行了处理,确保数据质量。")

      c.drawString(30, height - 140, "2. 数据分析:")
      c.drawString(30, height - 160, " - 按道路和时间段汇总数据,计算了车流量、车速和交通事故率。")
      c.drawString(30, height - 180, " - 发现高峰时段和高事故率区域。")

      c.drawString(30, height - 200, "3. 优化建议:")
      c.drawString(30, height - 220, " - 在高流量时段适当延长信号灯周期。")
      c.drawString(30, height - 240, " - 在事故高发区域加强交通管理。")

      • 添加图片(可视化图表)*
        c.drawImage("traffic_heatmap.png", 30, height - 450, width=500, height=300)
        c.drawImage("traffic_peak_times.png", 30, height - 780, width=500, height=300)
        c.drawImage("traffic_accident_distribution.png", 30, height - 1110, width=500, height=300)
        c.drawImage("signal_cycle_traffic_flow.png", 30, height - 1440, width=500, height=300)
      • 关闭并保存PDF*
        c.save()

      使用 reportlab 库创建了一个 PDF 报告。
      报告包含标题、分析过程、优化建议和图表。
      图表通过 drawImage 方法嵌入到 PDF 中。
      最终报告被保存为 analysis_report.pdf


generate_pdf_report()

# 7. 提供优化建议
high_accident_areas = road_summary[road_summary['交通事故率'] > 0.01]
peak_traffic_times = road_summary[road_summary['车辆数目'] > 400]

print("高风险事故区域(事故率 > 1%):")
print(high_accident_areas[['日期', '道路', '时间段', '交通事故率']])

print("\n高峰时段交通流量:")
print(peak_traffic_times[['日期', '道路', '时间段', '车辆数目']])
根据分析结果,提供了两种优化建议:
高风险事故区域(事故率大于 1%),需要加强交通管理。
高峰时段交通流量较大,可能需要调整信号灯周期等交通控制措施。
# 假设建议:在高流量时段适当延长信号灯周期,并且在事故高发区域加强交通管理。

signal_cycle_traffic_flow.png
traffic_accident_distribution.png
traffic_heatmap.png
traffic_peak_times.png

样例.pdf

]]>
<![CDATA[bookstrap基础一:自适应]]> /index.php/posts/247.html 2024-09-04T05:10:00+00:00 2024-09-04T05:10:00+00:00 种花家 http://zy种花家.cn 首先搜索bootstrap4菜鸟教程找到Bootstrap 4 CDN
bootstrap.png

复制粘贴
bootstrap1.png
效果如图
bootstrap2.png

]]>
<![CDATA[日记:成功用域名解析部署GitHub]]> /index.php/posts/242.html 2024-06-25T08:29:00+00:00 2024-06-25T08:29:00+00:00 种花家 http://zy种花家.cn 这几天一直试着能不能用域名部署GitHub的项目因为看到安知鱼大佬的文章
教程
我想着自己也可以弄一个因为GitHub的域名有点长而且不好听就自己买了一个,
但是文件都上传成功了就是访问不了
图片
后来发现是主分支和副分支有问题就是main和master

注意 :一定要看清楚和修改分支不然就会有问题

项目地址
也可以用vercel或Cloudflare来部署
最后查看qsmhx.cn
qsmhx

]]>
<![CDATA[基于butterfly主题的基础上利用高德地图api key加一个侧边电子时钟]]> /index.php/posts/239.html 2024-06-06T08:27:00+00:00 2024-06-06T08:27:00+00:00 种花家 http://zy种花家.cn 如图:
可以看看安知鱼的
https://blog.anheyu.com/posts/fc18.html
首先要看看之前有没有搞过类似的时钟如果有就在git里面执行
npm uninstall hexo-butterfly-clock或者npm uninstall hexo-electric-clock
之后安装
npm install hexo-butterfly-clock-anzhiyu --save
添加配置信息,我是直接在主题里面的config添加的这个看个人在哪添加

# electric_clock
# see https://blog.anheyu.com/posts/fc18.html
electric_clock:
  enable: true # 开关
  priority: 5 #过滤器优先权
  enable_page: all # 应用页面
  exclude:
  # - /posts/
  # - /about/
  layout: # 挂载容器类型
    type: class
    name: sticky_layout
    index: 0
  loading: https://cdn.cbd.int/hexo-butterfly-clock-anzhiyu/lib/loading.gif #加载动画自定义
  clock_css: https://cdn.cbd.int/hexo-butterfly-clock-anzhiyu/lib/clock.min.css
  clock_js: https://cdn.cbd.int/hexo-butterfly-clock-anzhiyu/lib/clock.min.js
  ip_api: https://widget.qweather.net/simple/static/js/he-simple-common.js?v=2.0
  qweather_key: # 和风天气key
  gaud_map_key: # 高得地图web服务key
  default_rectangle: false # 开启后将一直显示rectangle位置的天气,否则将获取访问者的地理位置与天气
  rectangle: 112.982279,28.19409 # 获取访问者位置失败时会显示该位置的天气,同时该位置为开启default_rectangle后的位置

然后注意要对好格式不然就要像我一下像一个无头苍蝇一样到处找最重要的还是
qweather_key: # 和风天气key
gaud_map_key: # 高得地图web服务key
这两个一定要配置不然也显示不了
具体教程还是看https://blog.anheyu.com/posts/fc18.html
写的很详细我这里就不多说了
最后hexo s或 hexo clean && hexo g && hexo s就行
样式

]]>
<![CDATA[cloudflare+GitHub制作一个简易的床图无限空间无需服务器和域名]]> /index.php/posts/220.html 2024-05-30T08:28:00+00:00 2024-05-30T08:28:00+00:00 种花家 http://zy种花家.cn cloudflare: https://dash.cloudflare.com/
github项目地址: https://github.com/cf-pages/Telegraph-Image
首先要注册一个cloud flare账号
Cloudflare注册步骤:
1.打开浏览器,访问Cloudflare官方网站: https://www.cloudflare.com
2.点击网页右上角的 "Sign Up"(注册)按钮。
3.输入您的电子邮件地址和设置密码,点击 "Create Account"(创建账户)123。
然后打开项目GitHub地址H{%V8L)R)4DKIZCDXGK9NG2.png
fork一下Create Fork
45.png我这里已经创建了一个
打开 Cloudflare Dashboard,进入 Pages 管理页面,选择创建项目,选择连接到 Git 提供程序,选择好刚刚操作的 GitHub 账号以及对应的存储库,点击开始设置即可。![47.png]
48.png
49.png
50.png
最后这样就成功了

参考其他博主 https://www.dujin.org/22073.html
教程视频参考云凡博主 https://www.bilibili.com/video/BV1fz421m718/?spm_id_from=333.1007.top_right_bar_window_history.content.click&vd_source=4d1859c2276cb6ea0f2afc467eaf7c7c

]]>
<![CDATA[hexo+git+GitHub制作一个简易网站]]> /index.php/posts/202.html 2024-05-24T04:59:00+00:00 2024-05-24T04:59:00+00:00 种花家 http://zy种花家.cn hexo链接 https://hexo.io/zh-cn/
git链接 https://gitee.com/explore
GitHub链接 https://github.com/

前言
近些年来很多用户都喜欢使用 GitHub 来搭建 Hexo 静态博客网站,其最吸引人的莫过于完全免费使用,并且非常稳定。
虽然搭建时比较麻烦,有点折腾,但是配置完成后,基本不需要操心维护的事,甚至放了几年都忘记了,打开来看文章依然还在。
由于博主比较懒所以可能大部分都是参考别人的文章
我这里偷懒一下哈哈这个博主写的比较详细
https://zhuanlan.zhihu.com/p/443527549
安装完成之后打开git hexo v 一下就会显示版本号说明安装成功了Y0T<code>Q0R1NBH1FEN__]O</code>UTW.png
注册一个GitHub账号可以看看这个博主的文章
https://blog.csdn.net/m0_67906358/article/details/128808210
然后连接git GitHub可以看看这篇文章
https://zhuanlan.zhihu.com/p/370635512
之后就可以开始部署hexo了
https://go2think.com/build-blog-with-hexo-on-github-pages/
最后直接hexo s就可以了G4H2(@DIG@P7(RD9{A}O{D6.png
然后就不要动了CTRL+C会停止运行可以选中然后右键有了copy复制打开就行
1.png
2.png
3.png
我是加了butterfly主题感兴趣的可以去搜一下还是一个比较好的主题
基本上全部都部署完成了有不动的可以加我p 备注一下什么问题我可以帮你看一下当然能自己解决更好哈哈
本期内容就到此结束了下期再见!
如有侵权请告诉我,我立马改正!

]]>
<![CDATA[一个普通专科生,拿什么拯救你的未来?]]> /index.php/posts/192.html 2024-04-24T07:21:00+00:00 2024-04-24T07:21:00+00:00 种花家 http://zy种花家.cn 无意间看到一位博主写的一篇文章说实话感同身受
原文链接:https://blog.csdn.net/weixin_44985115/article/details/114589835

我的情况跟博主差不多去年开始做博客,我很庆幸刚刚开始还有大佬带着教我一下常用的知识但是因为种种原因大佬比较忙现在自己慢慢研究,记得刚刚开始看代码的时候一头雾水
1.png
4.png
5.png

但是静下心来慢慢看还是可以看到,我常常在思考为什么要写博客有什么作用意义在哪?
看到这篇文章我知道了找到了自己,第一是为了提升自己的能力第二就是为了更好的学习吧
生命不息,奋斗不止
​做人如果没有理想,跟咸鱼有什么区别出自《少林足球》-- 周星驰
是啊刚刚开始只是想着做一个网站写一些好的文章现在实现了想想道路还是很艰难的
就一个花瓣效果我就改了两天当成功的时候还是很开心的因为我做到了
我认为应该勇于挑战自己的极限来提升自己的实力
别去羡慕别人有什么那还不如自己努力来的实在
因为你只看到他成功了没有看到背后努力的过程
人们通常只看结果不看过程成为了普遍现象
相信在未来的自己再看到这篇文章时一定会感慨当时做的决定
总有人要赢,为什么不能是我!
加油相信自己一定可以!

]]>
<![CDATA[]]> /index.php/posts/189.html 2024-04-23T10:07:00+00:00 2024-04-23T10:07:00+00:00 种花家 http://zy种花家.cn <![CDATA[测试API]]> /index.php/posts/186.html 2024-04-21T06:50:00+00:00 2024-04-21T06:50:00+00:00 种花家 http://zy种花家.cn https://app.nuoyis.net/acg
https://t.mwm.moe/pc?12
https://server-api.nuoyis.net/acg/?yasuo=1?5803

]]>
<![CDATA[看板娘]]> /index.php/posts/185.html 2024-04-21T05:52:00+00:00 2024-04-21T05:52:00+00:00 种花家 http://zy种花家.cn 看着别人博客主页的看板娘好萌好贴心,自己也想弄一个啊此处记录自己的学习实践过程,也供大家参考我认为一个不太够所以我弄了两个哈哈题外话.
首先第一个我是参考CSDN里的博主燕穗子博客
https://blog.csdn.net/m0_64346035/article/details/124436138?spm=1001.2014.3001.5506
421.png
XQ5H0(C9K46({IDT_~K%}K3.png

他是直接添加在PHP里面但是有时候可能加载不出来要耐心等待一下因为我弄这个搞了两天才出来的有时候不太稳定


https://www.cnblogs.com/pumpkinhlk/p/15410970.html
https://www.cnblogs.com/eve-d/p/15683541.html
第二个是在typecho里的直接修改外观改自定义CSS样式和自定义body标签末尾位置内容,自定义Footer内容可加可不加
CSS代码:

*{
transition: all 0.4s;
}

home {

margin: 0 auto;
width: 80%;/原始65/
min-width: 980px;/页面顶部的宽度/
">rgba(245, 245, 245, 0.7);
padding: 30px;
margin-top: 50px;
margin-bottom: 50px;
box-shadow: 0 2px 6px rgba(100, 100, 100, 0.3);
}
body {
background-image: url("http://ww4.sinaimg.cn/large/637d0877gw1exlma5gj0wj21hc0u04p6.jpg");
background: rgba(12, 100, 129, 1) url('http://images.cnblogs.com/cnblogs_com/Penn000/1013849/o_123.jpg') fixed no-repeat;
background-position: 50% 5%;
background-size: cover;
}

navList li{

cursor: pointer;
transition: all 0.2s;
}

navList li:hover {

transform: scale(1.5) rotate(360deg);
color:#FF0;
opacity:0.5;
}

blogTitle {

height: 100px; /高度/
clear: both;
">rgba(245, 245, 245, 0);
}

blogTitle h1 {

font-size: 36px;
font-weight: bold;
line-height: 1.8em;/原始 1.6em/
margin-top: 10px;/原始 15px /
color: #548B54;
}

blogTitle h2 {

font-weight: normal;
font-size: 17px;/原始 16px ;font-size: 1.0rem;/
line-height: 1.8;
color: #111;
font-weight: bold;
text-align: right;
float: right;
}

navigator{

">rgba(33, 160, 139, 0.9);
}

navList a:link, #navList a:visited, #navList a:active{

color: #eee;
font-size: 18px;
font-weight: bold;
}
.blogStats{
color: #eee;
}
.postTitle {
border-left: 8px solid rgba(33, 160, 139, 0.68);
margin-left: 10px;
margin-bottom: 10px;
font-size: 20px;
float: right;
width: 100%;
clear: both;
}
.postTitle a:link, .postTitle a:visited, .postTitle a:active {
color: #21759b;
transition: all 0.4s linear 0s;
}
.postTitle a:hover {
margin-left: 30px;
color: #0f3647;
text-decoration: none;
}
.postCon {
float: right;
line-height: 1.5em;
width: 100%;
clear: both;
padding: 10px 0;
}

.day .postTitle a {
padding-left: 10px;
}
.day {
background: rgba(255, 255, 255, 0.5);
}
/文章附加信息/
.postDesc {
background: url(images/posted_time.png) no-repeat 0 1px;
color: #757575;
float: left;
width: 100%;
clear: both;
text-align: left;
font-family: "微软雅黑" , "宋体" , "黑体" ,Arial;
font-size: 13px;
padding-right: 20px;/5px padding-left: 90px;posted 发表时间左边距离/
margin-top: 20px;
line-height: 1.8;
padding-bottom: 35px;
}

.newsItem, .catListEssay, .catListLink, .catListNoteBook, .catListTag, .catListPostCategory,
.catListPostArchive, .catListImageCategory, .catListArticleArchive, .catListView,
.catListFeedback, .mySearch, .catListComment, .catListBlogRank, .catList, .catListArticleCategory ,#blog-calendar
{
background: rgba(255, 255, 255, 0.5);
margin-bottom: 35px;
word-wrap: break-word;
}

.CalTitle{
background: rgba(255, 255, 255, 0);
}
.catListTitle{
">rgba(33, 160, 139, 0.9);
}

topics{

background: rgba(255, 255, 255, 0.5);
}

.c_ad_block{
display: none;
}

tbCommentBody{

width: 100%;
height: 200px;
background: rgba(255, 255, 255, 0.5);
}

q{background: rgba(255, 255, 255, 0);}

.CalNextPrev{background: rgba(255, 255, 255, 0);}
但是我觉得太长了因为太长了看起来很麻烦
canvas#live2dcanvas {
border: 0 !important;
left: 0;
}
这个相对了说比较适合
最重要的还是自定义body标签末尾位置内容

看板娘的图形代码地址合集:https://www.lanol.cn/post/305.html
还可以自己弄一张图片上去还有聊天内容也可以修改可以看看上面的链接
以上都是借鉴大佬们的如有侵权请及时告诉我,我立即修改!
其他版本:https://paugram.com/coding/add-poster-girl-with-plugin.html

]]>