I'm trying to graph a set of data I have my y values as
y=[129.000, 128.000, 140.000, 150.000]
x=["1/2018", "2/2018", "3/2018", "4/2018"]
# plot the data itself
pylab.plot(x,y,‘o’)
# calc the trendline (it is simply a linear fitting)
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])
I keep getting:
ufunc 'add' did not contain loop with signature matching type dtype ('S32') ('S32') ('S32')
I have tried using epoch dates as well but that didn’t work. I’m simply trying to plot a trend of prices to dates and extend the trend line past the dates. I know the error has to do with the labels being strings. I’m not sure how to plot the trendline with string labels. The guide I was using has date labels so I’m not sure what I’m doing wrong.
http://widu.tumblr.com/post/43624347354/matplotlib-trendline
Any thoughts?