How does some get the y
values from the red trend line generated from the source code below? I am no math expert.
As for the code below from How to add trendline in python matplotlib dot (scatter) graphs?
#random inputs for x and y
x = np.random.uniform(low=0.5, high=13.3, size=(50,))
y = np.random.uniform(low=0.5, high=13.3, size=(50,))
# plot the data itself
pylab.plot(x,y,'o')
# calc the trendline
z = numpy.polyfit(x, y, 1)
p = numpy.poly1d(z)
pylab.plot(x,p(x),"r--")
# the line equation:
print "y=%.6fx+(%.6f)"%(z[0],z[1])
When I print the value of p(x)
, the expected values of y to plot the red trend line.
[7.25072088 7.74580974 7.707636 7.57456601 7.72771792 7.36682509
7.36216195 7.45937086 7.47592622 7.76663313 7.71256734 7.68601844
7.34777885 7.2552914 7.28729136 7.4828444 7.25690455 7.47861776
7.48472596 7.63791435 7.79364877 7.79382845 7.45020348 7.5488981
7.29478413 7.27191799 7.47409563 7.26783249 7.49132469 7.2515923
7.40558937 7.55062512 7.46004735 7.4094514 7.69985713 7.23891764
7.50790404 7.38789488 7.23477781 7.59598148 7.49460819 7.62039958
7.67580303 7.40553616 7.61933389 7.60038837 7.76048006 7.41307834
7.28136679 7.5063726 ]
If this an upward moving trend, should the array elements increase from start to end? As you can see, there are element previous values higher than then current one. Should there not be a steady incline which where the next element would ALWAYS be the higher than the previous element? Call me confused.