1 回答

TA貢獻1831條經(jīng)驗 獲得超10個贊
最簡單、最一致的方法是為每個算法制作散點圖。此外,您可能希望為此使用面向對象的接口。
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
def calculate_runtimes(algo, data, sizes):
if algo == 'name1':
# return timings for algorithm 1 given data at given sizes
elif algo == 'name2':
# ...
algo_labels = ['name1', 'name2', 'name3', 'name4', 'name5']
sizes = [1, 2, 4, 8, 16]
algo_runtimes = {name: calculate_runtimes(name, dataset, sizes) for name in algo_labels}
colors = ['red', 'green', 'blue', 'yellow', 'black']
x_positions = [len(dataset)*size for size in sizes]
for (label, runtimes), color in zip(algo_runtimes.items(), colors):
ax.scatter(x_positions, runtimes, color=color, label=label)
ax.legend()
添加回答
舉報