科研04——python如何利用列表的数据画图
放一个代码,以后方便
import matplotlib.pyplot as plt
def draw_number(step, number_V2V, number_V2I, number_finished, number_number_all_taskd):
plt.rcParams['font.sans-serif'] = ['SimHei']#用来正常显示中文标签
plt.rcParams['axes.unicode_minus'] = False#用来正常显示负号
# plt.bar(step,cost, color="red")
# plt.plot(step,cost)
plt.plot(step, number_finished, color = "red", label = "已经完成的任务个数")
plt.plot(step, number_V2V, color = "blue", label = "offload给车的任务个数")
plt.plot(step, number_V2I, color = "green", label = "offload给MEC的任务个数")
plt.plot(step, number_number_all_taskd, color = "orange", label = "总任务个数")
plt.legend()#显示图例
plt.xlabel("step")
plt.ylabel("task_number")
plt.title("随着时间变化的相应的任务个数")
plt.show()#画图
drawing.draw_number(stepd, number_V2Vd, number_V2Id, number_finishedd, number_number_all_taskd)
输出结果:
通过上面的输出结果和代码对应着看,很容易理解