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,
)
相关推荐
别抢我的锅包肉12 分钟前
【FastAPI】 响应类型详解:从默认 JSON 到自定义响应
python·fastapi
leaves falling19 分钟前
C++ string 类:从入门到模拟实现
开发语言·c++
智算菩萨23 分钟前
【Tkinter】15 样式与主题深度解析:ttk 主题系统、Style 对象与跨平台样式管理实战
开发语言·python·ui·ai编程·tkinter
子非鱼@Itfuture37 分钟前
`<T> T execute(...)` 泛型方法 VS `TaskExecutor<T>` 泛型接口对比分析
java·开发语言
weixin_4193497942 分钟前
Python 项目中生成 requirements.txt 文件
开发语言·python
林恒smileZAZ1 小时前
前端大屏适配方案:rem、vw/vh、scale 到底选哪个?
开发语言·前端·css·css3
第一程序员1 小时前
Python与区块链:非科班转码者的指南
python·github
liu****1 小时前
LangChain-AI应用开发框架(六)
人工智能·python·langchain·大模型应用·本地部署大模型
witAI1 小时前
**AI仿真人剧制作2025推荐,专业团队与创新技术引领未来**
人工智能·python
liuyao_xianhui2 小时前
优选算法_最小基因变化_bfs_C++
java·开发语言·数据结构·c++·算法·哈希算法·宽度优先