绘制折线图

colors = ['red', 'green', 'blue'] for i in range(len(partitions)): plt.plot(customer_sizes, average_costs[i], label="p=" + str(partitions[i]), linestyle='-', marker='o', color=colors[i])

设置标题和坐标轴标签

plt.title("Average delivery cost")

plt.xlabel("Customer scale") plt.ylabel("Average delivery cost")

设置斜体

leg = plt.legend() for text in leg.get_texts(): if text.get_text().startswith("p="): text.set_fontstyle('italic') elif text.get_text().startswith("="): text.set_text(text.get_text().replace("=", " = "))

plt.show(

修改代码:# 绘制折线图colors = red green bluefor i in rangelenpartitions pltplotcustomer_sizes average_costsi label=p= + strpartitionsi linestyle=- marker=o color=colorsi# 设置标题和坐标轴标签# plttitleAverage deliver

原文地址: https://www.cveoy.top/t/topic/ioky 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录