x
|
y
|
80.5
|
44
|
70.5
|
35
|
57
|
20.4
|
66
|
33
|
68
|
31
|
72
|
35
|
52
|
18.5
|
73.5
|
37
|
53
|
26
|
In python, we could make two lists, one for x-values and one for y-values.
xVals = [80.5, 70.5, 57, 66, 68, 72, 52, 73.5, 53]
yVals = [44, 35, 20.4, 33, 31, 35, 18.5, 37, 26]
This time, we're going with the standard Spyder Python editor, and not entering code directly into the iPython console. We've defined a function that handles our plotting instructions. The code should be pretty easy to follow. This time, we didn't set the range for the x-values; Pylab handled this for us. Also, in pylab.plot, we have 'bo' instead of just 'b'; this plots blue circles for the data points instead of a blue curve based on them. We've also added a legend, though we haven't made much use of it yet. loc = 'best' allows pylab to choose the best location for the legend so it doesn't get in the way of the important stuff.
![]() |
Call the function and ask pylab to show the graph |
![]() |
Our data |
An $R^{2}$ value of around 0.90 isn't too bad.
Next time, we'll use a data set contained in a text file.
No comments:
Post a Comment