Search code examples
pythonpandasmatplotlibbokeh

python multiple x vs y line plots with unique z values


I've got a pandas dataframe that looks like this:

Iteration    output          Temperature
1            23                 -40
1            26                  -7 
1            20                  25 
1            30                  78
2            34                 -40
2            33                  -7 
2            32                  25 
2            36                  78 
3            34                 -40
3            37                  -7 
3            45                  25 
3            43                  78 

I want to get multiple line plots of output(y) vs temperature (x) for unique iteration values.

For the example data, I would get three overlaid line plots, for the three unique iteration values.

How do I do this in python?

Do I get a list of unique iteration values and then use that to filter out the dataframe and individually plot them all?


Solution

  • for group,records in df.groupby('iteration'):
        plt.plot(records['output'],records['temperature'],legend=str(group))
    

    Is how i would probably do it