删除索引级别,转置和绘图。
df.reset_index('is_greedy', drop=True).T.plot()
import pandas as pd import numpy as np df = pd.DataFrame(np.random.randint(30, 50, (3, 11)), index=['no_transfer', 'transfer', 'random_transfer']) df = df.set_index(10, append=True) df.index.names=['config', 'is_greedy'] # 0 1 2 3 4 5 6 7 8 9 #config is_greedy #no_transfer 40 35 49 47 36 48 47 39 48 38 32 #transfer 33 35 33 45 38 38 45 36 30 46 36 #random_transfer 36 32 41 36 41 37 35 40 42 49 32 df.reset_index('is_greedy', drop=True).T.plot()
或者遍历行:
import matplotlib.pyplot as plt fig, ax = plt.subplots() for idx, row in df.iterrows(): ax.plot(df.columns, row, label=idx[0]) plt.legend() plt.show()