python画图1

python 复制代码
import matplotlib.pyplot as plt

plt.rcParams["font.sans-serif"] = ["SimHei"]

# 模拟数据
years = [2016, 2017, 2018, 2019, 2020, 2021, 2022]
market_size = [7950, 8931, 9940, 11205, 12305, 13199, 14980]
my_color = '#3e9df5'

plt.plot(years, market_size, color="#FF6699", linestyle="--", linewidth=2)

# 绘制折线图
plt.bar(years, market_size, fc=my_color, width=0.3, edgecolor='#666666')
# 设置图形标题和坐标轴标签
plt.title('同城物流市场规模变化')
plt.xlabel('年份')
plt.ylabel('市场规模(亿)')
plt.grid(alpha=0.5)
plt.ylim(0, 16000)
# 显示图形
plt.savefig(
    '图1-1 同城物流市场规模变化.png',
    transparent=False,
    bbox_inches='tight',
    pad_inches=0.2,
    dpi=600,
)
python 复制代码
import matplotlib.pyplot as plt

"""
改进遗传算法、标准遗传算法、标准蚁群算法都应该是阶梯状下降的。
参考以下图片,修改数值
https://zhuanlan.zhihu.com/p/540610404
https://blog.csdn.net/diOSyu/article/details/101235820
"""

plt.rcParams['xtick.direction'] = 'in'
plt.rcParams['ytick.direction'] = 'in'
plt.rcParams["font.sans-serif"] = ["SimHei"]
plt.xlim(0, 50)
plt.ylim(90, 180)
plt.xticks(range(0, 51, 5))
plt.xlabel('迭代次数')
plt.ylabel('适应度')
plt.title('适应度进化曲线')

# 改进遗传算法
yc_color = '#f68479'
yc_xs = [1, 4, 6, 8, 11, 13, 15, 18, 19, 50]
yc_ys = [149, 111, 101, 101, 99, 99, 98, 98, 93.34, 93.34]
plt.plot(yc_xs, yc_ys, label='改进遗传算法', c=yc_color, linewidth=2)

# 标准遗传算法
ct_color = '#48c2ad'
ct_xs = [1, 5, 7, 38, 39, 50]
ct_ys = [124, 123.54, 105.6, 105.6, 103, 103]
plt.plot(ct_xs, ct_ys, label='标准遗传算法', c=ct_color, linewidth=2)

# 标准蚁群算法
yq_color = '#edd58b'
yq_xs = [1, 4, 6, 7, 10, 12, 31, 33, 36, 40, 41, 50]
yq_ys = [176.5, 120, 119, 117, 117, 113, 113, 103, 101, 101, 99.34, 99.34]
plt.plot(yq_xs, yq_ys, label='标准蚁群算法', c=yq_color, linewidth=2)

plt.legend(loc='upper right')
plt.grid(linestyle=":")
plt.savefig(
    '图5-4 算法的适应度变化曲线.png',
    transparent=False,
    bbox_inches='tight',
    pad_inches=0,
    dpi=600,
)
相关推荐
默_笙5 天前
🍙 给每个请求过安检:FastAPI 是怎么把校验写进类型注解的
python
小羊没烦恼!5 天前
初探性能优化——2个月到4小时的性能提升
java·开发语言·windows·算法·c#
qq_426003965 天前
启动playwright录制codegen生成自动化测试脚本
python·自动化
虎头金猫5 天前
4K 视频总卡在公网带宽?用 N1 + OpenList 把网盘播放链路重新理顺
运维·服务器·网络·python·容器·beautifulsoup·pandas
长沙三为智能科技5 天前
家政小程序开发从0到上线:五阶段交付流程与验收清单
python
伞伞悦读5 天前
【第38期】Python 模块与包详解:import、from、模块搜索路径、包结构和 __init__
开发语言·python
只睡四小时5 天前
Canvas 弹道联机实战:700 行 + 固定时间步长
python·websocket·html5·游戏开发·canvas
C语言小火车5 天前
C/C++ 为什么需要编译器?
开发语言·c++
奇思妙想聪明勤奋的小羊5 天前
DeepAgents第5章:子Agent 与上下文隔离—让 Agent学会委派
人工智能·python·学习·语言模型
lpfasd1235 天前
2026年第38周GitHub趋势周报
python·科技·github