Python Forum
python matplotlib groupby - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: python matplotlib groupby (/thread-32415.html)



python matplotlib groupby - okpython - Feb-08-2021

I am trying to use matplotlib to plot the data to mimic the behaviour in the excel screenshot below. I am not able to groupby twice, subsequently, I am getting a join between the 2 series, and they're only being plotted in the single series.

My code:
fig, ax = plt.subplots(figsize=(8,6))
for lab, d in df.groupby(['label']):
    df.groupby(['model'])
    ax.plot(df[df.label==label]["xValue"],df[df.label==label].yValue, label=label, marker='o')
The 2nd groupby is not working.
How can I fix this?

dataframe:

Output:
model label run yValue xValue v3 SL 101 -5 40 v3 LS 201 -6 42 v3 MS 301 -5.5 41 v4 SL 102 -2 50 v4 LS 202 -4 52 v4 MS 302 -3 51