How to plot multiple lines in one figure in Pandas Python based on data from multiple columns?
<p>I have a dataframe with 3 columns, like this:</p>

<pre><code>df['year'] = ['2005, 2005, 2005, 2015, 2015, 2015, 2030, 2030, 2030']
df['name'] = ['A', 'B', 'C', 'A', 'B', 'C', 'A', 'B', 'C']
df['weight'] = [80, 65, 88, 65, 60, 70, 60, 55, 65]
</code></pre>

<p>how can I plot a line for A, B and  C, where it shows how their weight develops through the years. So I tried this: </p>

<pre><code>df.groupby("euro").plot(x="year", y="MKM")
</code></pre>

<p>However, I get multiple plots and that is not what I want. I want all those plots in one figure. </p>

<p>Does this produce what you're looking for?</p>

<pre><code>import matplotlib.pyplot as plt
fig,ax = plt.subplots()

for name in ['A','B','C']:
    ax.plot(df[df.name==name].year,df[df.name==name].weight,label=name)

ax.set_xlabel("year")
ax.set_ylabel("weight")
ax.legend(loc='best')
</code></pre>

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

python pandas matplotlib plot