How to plot columns from a multi-indexed DataFrame in pandas

If the output of the parameter study is stored in a multi-indexed DataFrame, the columns should be plotted and labelled using the multi-index data to annotate the graphs in the diagram with corresponding parameters.

For a two-level multi-index parameter-study.csv, it can be done like this:

import pandas as pd
import matplotlib.pyplot as plt
from matplotlib import rcParams
 
rcParams["figure.dpi"] = 200
 
dFrame = pd.read_csv("parameter-study.csv", index_col=[0,1])
 
for idx, dFrameSubset in dFrame.groupby(level=[0, 1]):
    plt.plot(dFrameSubset["time"], dFrameSubset["Linf velocity error"], label="N=%d, rho=%d" % (idx[0], idx[1]))
 
plt.legend()

The corresponding data file and Jupyter notebook can be downloaded here:

See also