Pandas groupby object in legend on plot
<p>I am trying to plot a pandas <code>groupby</code> object using the code <code>fil.groupby('imei').plot(x=['time'],y = ['battery'],ax=ax, title = str(i))</code> </p>

<p>The problem is the plot legend lists <code>['battery']</code>as the legend value. Given it's drawing a line for each item in the <code>groupby</code> object, it makes more sense to plot those values in the legend instead. However I'm not sure how to do that. Any help would be appreciated.</p>

<p>Data</p>

<pre><code>                 time             imei  battery_raw
0 2016-09-30 07:01:23  862117020146766        42208
1 2016-09-30 07:06:23  862117024146766        42213
2 2016-09-30 07:11:23  862117056146766        42151
3 2016-09-30 07:16:23  862117995146745        42263
4 2016-09-30 07:21:23  862117020146732        42293
</code></pre>

<p>Full code </p>

<pre><code>for i in entity:
    fil = df[(df['entity_id']==i)]
    fig, ax = plt.subplots(figsize=(18,6))
    fil.groupby('imei').plot(x=['time'],y = ['battery'],ax=ax, title = str(i))  
    plt.legend(fil.imei)
    plt.show()
</code></pre>

<p>Current plot </p>

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