Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
python matplotlib groupby
#1
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
Larz60+ write Feb-09-2021, 01:20 AM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time. Please use bbcode tags on future posts.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to iterate Groupby in Python/PySpark DrData82 2 2,709 Feb-05-2022, 09:59 PM
Last Post: DrData82
  Matplotlib: How do I convert Dates from Excel to use in Matplotlib JaneTan 1 3,161 Mar-11-2021, 10:52 AM
Last Post: buran
  How to groupby Months showing average order value - Pandas & matplotlib Rwood90 0 1,837 Oct-20-2020, 12:53 PM
Last Post: Rwood90
  Use of & operator, groupby in python abhi1693r 0 1,566 Mar-11-2020, 02:25 PM
Last Post: abhi1693r
  Matplotlib graphing help (dual y axis, groupby, filter) keml 0 2,166 Feb-07-2020, 02:35 AM
Last Post: keml

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020