kroonike
kroonike

Reputation: 1129

Python, create plot from DataFrame

I have a DataFrame that looks as follows:

        C    gamma  precision
0     1.0  0.00001   0.044040
1     1.0  0.00010   0.044063
2     1.0  0.00100   0.349788
3     1.0  0.01000   0.359441
4     1.0  0.10000   0.367857
5    10.0  0.00001   0.090369
6    10.0  0.00010   0.347510
7    10.0  0.00100   0.358762
8    10.0  0.01000   0.354194
9    10.0  0.10000   0.337157
10   50.0  0.00001   0.340957
11   50.0  0.00010   0.356938
12   50.0  0.00100   0.357969
13   50.0  0.01000   0.365525
14   50.0  0.10000   0.318042
15  100.0  0.00001   0.348168
16  100.0  0.00010   0.358309
17  100.0  0.00100   0.353821
18  100.0  0.01000   0.356823
19  100.0  0.10000   0.311630

I'm struggling with creating plot similar to this: enter image description here

Gamma is the X-axis, Precision is Y-axis and every line represents unique value of C.

Upvotes: 0

Views: 109

Answers (1)

Bart
Bart

Reputation: 10250

For plotting each line with a unique C you could do something like this:

pl.figure()
ax=pl.gca()
for c in df['C'].unique():
    df.loc[df['C'] == c].plot(ax=ax, x='gamma', y='precision', label='C: {}'.format(c))

df['C'].unique() creates an array with all unique values of C, df.loc[df['C'] == c] selects all rows with the same value of C, and by setting the x and y parameters of plot() you can plot one column versus another.

Upvotes: 3

Related Questions