pltplotn_values greedy_times label=Greedy pltplotn_values dp_times label=Dynamic Programming pltxlabelNumber of activities pltylabelExecution time pltlegend pltshow上述代码直线图改为曲线图
要将直线图改为曲线图,可以使用plt.plot()函数的第三个参数来指定线条样式。将代码修改如下:
plt.plot(n_values, greedy_times, label='Greedy', marker='o')
plt.plot(n_values, dp_times, label='Dynamic Programming', marker='o')
plt.xlabel('Number of activities')
plt.ylabel('Execution time')
plt.legend()
plt.show()
在上述代码中,我们添加了marker='o'参数来指定曲线上的数据点为圆形。这样就可以将直线图改为带有数据点的曲线图。
原文地址: https://www.cveoy.top/t/topic/hH1f 著作权归作者所有。请勿转载和采集!