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>Whatever column is used as <code>x</code> is removed from the DataFrame before <code>y</code> is looked up.  (Or, more technically, <code>x</code> is set as the index, which means its no longer available as a column.)  So if you do <code>.plot(x=0, y=0)</code>, the <code>x=0</code> means "use the first positional column", and the <code>y=0</code> means "use whatever will be the first positional column after the x column is removed".</p>

<p>Needless to say this could get confusing, because whether <code>y</code> shifts in position depends on whether it was before or after <code>x</code>.  So if you do <code>.plot(x=3, y=1)</code>, then y really is column #1, but if you do <code>.plot(x=0, y=1)</code>, then y is actually column #2 (it becomes number 1 after column 0 is removed).</p>

python python-2.7 pandas matplotlib dataframe