Plotting more than two columns in python using Panda from a CSV file
<p>I am very new to python and coding in general. I have a CSV file that has the first row a string of flight attributes (ie. time, speed, heading, battery voltage etc.) I want to be able to plot time vs speed vs battery voltage. Or battery voltage vs speed. I have tried several examples, however, every example I have seen it is either plots everything in the CSV file which I do not want. Or the csv file only has 2 columns.</p>

<pre><code>CSV File format:
time(ms), ground_speed, battery_voltage(v), airspeed(m/s)
1322,45,12,42
1342,64,11,60
1352,30,11,27

import pandas as pd
from pandas import DataFrame, read_csv
import numpy as np
import matplotlib.pyplot as plt
import matplotlib
matplotlib.style.use('ggplot')


df = pd.DataFrame.from_csv('myflight.csv', index_col=False)

df.plot(x='mSec', y='Airspeed(m/s)', color="g")
df.plot(x='mSec', y='AS_Cmd(m/s)', color="r")
</code></pre>

<p>My issue with this it always plots vs the first index which is time. Also, I get two separate graphs. How do I join both airspeed and AS_Cmd into one graph and be able to plot someone else beside time vs something else?</p>

<p>You can simply set your desired index and plot everything in one shot:</p>

<pre><code>import matplotlib

matplotlib.style.use('ggplot')

df.set_index('time(ms)')[['ground_speed','battery_voltage(v)']].plot(rot=0, figsize=(16,10))
</code></pre>

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

python pandas plot