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,
)
相关推荐
zone773920 小时前
001:简单 RAG 入门
后端·python·面试
F_Quant20 小时前
🚀 Python打包踩坑指南:彻底解决 Nuitka --onefile 配置文件丢失与重启报错问题
python·操作系统
允许部分打工人先富起来21 小时前
在node项目中执行python脚本
前端·python·node.js
IVEN_21 小时前
Python OpenCV: RGB三色识别的最佳工程实践
python·opencv
haosend1 天前
AI时代,传统网络运维人员的转型指南
python·数据网络·网络自动化
曲幽1 天前
不止于JWT:用FastAPI的Depends实现细粒度权限控制
python·fastapi·web·jwt·rbac·permission·depends·abac
IVEN_2 天前
只会Python皮毛?深入理解这几点,轻松进阶全栈开发
python·全栈
Ray Liang2 天前
用六边形架构与整洁架构对比是伪命题?
java·python·c#·架构设计
AI攻城狮2 天前
如何给 AI Agent 做"断舍离":OpenClaw Session 自动清理实践
python
千寻girling2 天前
一份不可多得的 《 Python 》语言教程
人工智能·后端·python