Python Pandas plot multiindex specify x and y
<p>Below is an example <code>DataFrame</code>.</p>

<pre><code>           joaquin     manolo
xx 0  0.000000e+00  44.000000
   1  1.570796e+00  52.250000
   2  3.141593e+00  60.500000
   3  4.712389e+00  68.750000
   4  6.283185e+00  77.000000
yy 0  0.000000e+00  37.841896
   1  2.078796e+00  39.560399
   2  5.292179e-17  41.026434
   3 -8.983291e-02  42.304767
   4 -4.573916e-18  43.438054
</code></pre>

<p>As you can see, the row index has two levels, <code>['xx', 'yy']</code> and <code>[0, 1, 2, 3, 4]</code>. I want to call <code>DataFrame.plot()</code> in such a way that it will produce two subplots, one for <code>joaquin</code> and one for <code>manolo</code>, and where I can specify to use <code>data.loc["xx", :]</code> for the domain data and to use <code>data.loc["yy", :]</code> for the ordinate data. In addition, I want the option to supply the subplots on which the plots should be drawn, in a list (or array) of <code>matplotlib.axes._subplots.AxesSubplot</code> instances, such as those that can be returned by the <code>DataFrame.hist()</code> method. How can this be done?</p>

<h3>Generating the data above</h3>

<p>Just in case you're wondering, below is the code I used to generate the data. If there is an easier way to generate this data, I'd be very interested to know as a side-note.</p>

<pre><code>joaquin_dict = {}
xx_joaquin = numpy.linspace(0, 2*numpy.pi, 5)
yy_joaquin = 10 * numpy.sin(xx_joaquin) * numpy.exp(-xx_joaquin)
for i in range(len(xx_joaquin)):
    joaquin_dict[("xx", i)] = xx_joaquin[i]
    joaquin_dict[("yy", i)] = yy_joaquin[i]

manolo_dict = {}
xx_manolo = numpy.linspace(44, 77, 5)
yy_manolo = 10 * numpy.log(xx_manolo)
for i in range(len(xx_manolo)):
    manolo_dict[("xx", i)] = xx_manolo[i]
    manolo_dict[("yy", i)] = yy_manolo[i]

data_dict = {"joaquin": joaquin_dict, "manolo": manolo_dict}
data = pandas.DataFrame.from_dict(data_dict)
</code></pre>

<p>Just use a for loop:</p>

<pre><code>fig, axes = pl.subplots(1, 2)
for ax, col in zip(axes, data.columns):
    data[col].unstack(0).plot(x="xx", y="yy", ax=ax, title=col)
</code></pre>

<p>output:</p>

<p><a href="http://i.stack.imgur.com/SrYbq.png" rel="nofollow"><img src="http://i.stack.imgur.com/SrYbq.png" alt="enter image description here"></a></p>

python pandas plot