自学内容网 自学内容网

python画图1

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,
)
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,
)

 


原文地址:https://blog.csdn.net/diOSyu/article/details/142430432

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!