Pandas plot dataframe by index, how it works?
<p>Given the data:</p>

<pre><code>Column1; Column2; Column3
1; 4; 6
2; 2; 6
3; 3; 8
4; 1; 1
5; 4; 2
</code></pre>

<p>With the following code I get the following graphic:</p>

<pre><code>import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_csv('test0.csv',delimiter='; ', engine='python')
df.plot(0,0)
plt.savefig('fig0.png')
</code></pre>

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

<p>And, with the following code I get the following graphic:</p>

<pre><code>import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_csv('test0.csv',delimiter='; ', engine='python')
df.plot(0,1)
plt.savefig('fig1.png')
</code></pre>

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

<p>What's the logic in <code>df.plot(m,n)</code>? Let's say I want to plot <code>Column2 X Column3</code>  what's <code>m</code> and <code>n</code>(<code>df.plot(2,3)</code>) ? </p>

<p>According to the <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.plot.html" rel="nofollow">documentation</a>, you can define <em>m</em> and <em>n</em> (<em>x</em> and <em>y</em> in the documentation) like this:</p>

<pre><code>df.plot(df.columns[1],df.columns[2])
</code></pre>

<ul>
<li>'m' should be -> <code>df.columns[1]</code> ,i.e., the column name of the position 1</li>
<li>'n' should be -> <code>df.columns[2]</code> ,i.e., the column name of the position 2</li>
</ul>

<p>If you want to use the positions, would be:</p>

<pre><code>df.plot(1,1)
</code></pre>

<p>The logic using position is: when we put <em>1</em> in the horizontal axis, this column is removed from the options for the vertical axis, so there is only two options available (with new indexes). Thats why <code>df.plot(0,0)</code> actually sets first and the next column as the data and <code>df.plot(1,1)</code> uses the second and last columns. I didn't found it in the documentation, I discovered it testing.</p>

<p>I think the idea is: makes no sense plot the same columns in axis x and y, so the first column given is not available for the other axis. I hope it help! =)</p>

<p><em>PS:It will plot in a weird zoom and position, but if you zoom out and move through the plot you will confirm that the values matches with the data of each column</em></p>

python python-2.7 pandas matplotlib dataframe