Complex legend layout


I have a plot with 9 lines, representing datasets with two varying parameters, say f_11, f_12, f_13, …, f_33. To make the plot (a bit) clearer, I encode the first parameter as the color of the line and the second one as the linestyle (so f_11 is red & dashed, f12 is red & dotted, f21 is green & dashed, f22 is green & dotted, etc.). So, for the legend, I would like to make a 3x3 table, looking like

param1 \ param2 | value1 | value2 | value3




(it probably is going to look terrible in a proportional font but hopefully you get the idea…).

Is there any way I can make this with matplotlib? An idea would be to make this box with LaTeX, but I need a way to plot the legend artists at the right position.