创建您的数据框,确保使用sort_values 按算法和num_ingress 进行排序。
import pandas as pd
algorithm = ['A', 'A', 'A', 'A', 'A', 'B', 'B', 'B', 'B', 'B']
num_ingress = [4, 2, 1, 3, 5, 4, 2, 1, 3, 5]
total_flow = [8000, 4000, 2000, 6000, 10000, 8000, 4000, 2000, 6000, 10000]
successful_flows = [5985, 3994, 1997, 5991, 1994, 5975, 3988, 1996, 5974, 5087]
dropped_flows = [2000, 0, 0, 0, 7991, 2005, 0, 0, 9, 4889]
df = pd.DataFrame({'algorithm': algorithm,
'num_ingress': num_ingress,
'total_flow': total_flow,
'successful_flows': successful_flows,
'dropped_flows': dropped_flows
})
df.sort_values(['algorithm', 'num_ingress'], inplace=True)
df
然后绘制
import matplotlib.pyplot as plt
import numpy as np
for i, algorithm in enumerate(df.groupby('algorithm')):
algorithm_df = pd.DataFrame(algorithm[1])
plt.subplot(1, 2, i+1)
plt.plot(algorithm_df['num_ingress'], algorithm_df[['total_flow', 'successful_flows', 'dropped_flows']])
plt.title("Algorithm {}".format(algorithm_df['algorithm'].values[0]))
plt.tight_layout()
plt.show()