修改代码:import matplotlibpyplot as pltpltrcfontfamily=Times New Roman size=12# 客户规模customer_sizes = 300 350 400 450 500 550 600# 分区数量partitions = 6 7 8# 平均配送成本average_costs = 342893 333376329729327279327
import matplotlib.pyplot as plt plt.rc('font',weight='bold',family='Times New Roman', size=12)
客户规模
customer_sizes = [300, 350, 400, 450, 500, 550, 600]
分区数量
partitions = [6, 7, 8]
平均配送成本
average_costs = [[34.2893, 33.3376,32.9729,32.7279,32.7143,32.6044,32.4504], [34.2878,33.7388,33.3372,32.9542,32.7115,32.3371,32.1999], [34.7602,33.6432,33.2217,33.1579,33.1209,32.8848,32.6923]]
绘制折线图
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", weight='bold') plt.ylabel("Average delivery cost", weight='bold')
设置斜体
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(
原文地址: https://www.cveoy.top/t/topic/iokN 著作权归作者所有。请勿转载和采集!