0

I have a pandas dataframe that looks like this:

       Nstrike     Nprem  TDays
0    0.920923  0.000123    2
1    0.951621  0.000246    2
2    0.957760  0.001105    2
..............................
16   0.583251  0.000491    7
17   0.613949  0.000614    7
18   0.675344  0.000368    7
..............................
100  1.013016  0.029592   27
101  1.043713  0.049730   27
102  1.074411  0.071218   27
etc.

I would like to plot a graph of col.1 vs col.2, in separate plots as selected by col.3, maybe even in different colors.

The only way I can see to do that is to separate the dataframe into discrete dataframes for each col.3 value.

Or I could give up on pandas and just make the col.3 subsets into plain python arrays.

I am free to change the structure of the dataframe if it would simplify the problem.

user1067305
  • 3,233
  • 7
  • 24
  • 29

1 Answers1

1

IIUC, you can use this as a skeleton, and customize it how you want:

for g, data in df.groupby('TDays'):
    plt.plot(data.Nstrike, data.Nprem, label='TDays '+str(g))
    plt.legend()
    plt.savefig('plot_'+str(g)+'.png')
    plt.close()

Your first plot will look like:

enter image description here

Your second:

enter image description here

And so on

sacuL
  • 49,704
  • 8
  • 81
  • 106