pltplotn_values greedy_times label=Greedy pltplotn_values dp_times label=Dynamic Programming pltxlabelNumber of activities pltylabelExecution time pltlegend pltshow将上述代码改为用np的曲线图
import numpy as np import matplotlib.pyplot as plt
n_values = np.array([10, 20, 30, 40, 50]) greedy_times = np.array([0.1, 0.5, 1.2, 2.3, 4.0]) dp_times = np.array([0.2, 0.8, 1.5, 3.0, 5.5])
plt.plot(n_values, greedy_times, label='Greedy') plt.plot(n_values, dp_times, label='Dynamic Programming') plt.xlabel('Number of activities') plt.ylabel('Execution time') plt.legend() plt.show()
原文地址: https://www.cveoy.top/t/topic/hH67 著作权归作者所有。请勿转载和采集!