0

I'm trying to make a view in Django which will take a list of numbers for the x and y axis and return an image much like the one produced from the code below. I need the linear regressor in the image as well.

Note: it doesn't have to be through using pylab, the output is what matters most.

from pylab import *

x = [1,54,4,5,67,3,12]
y = [3,23,67,1,3,43,7]

(m, b) = polyfit(x,y,1)
print(b)
print(m)

yp = polyval([m,b],x)

plot(x, yp)
scatter(x, y)
grid(True)

xlabel('x')
ylabel('y')

show()

I found code similar to this here.

As always, thanks for the help!

Ravaal
  • 3,233
  • 6
  • 39
  • 66
  • 1
    You need a view that takes the numbers via GET or POST request data which you can find in any basic Django tutorial and generates the image on the fly as your code does. Then have a look here how to return an image as http response: http://stackoverflow.com/questions/1074200/serve-a-dynamically-generated-image-with-django – djangonaut Sep 22 '15 at 18:45
  • I got it. Thank you. – Ravaal Sep 23 '15 at 18:54

0 Answers0