【发布时间】:2018-05-22 18:17:05
【问题描述】:
我正在尝试绘制一组数据,我的 y 值为
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])
我不断得到:
ufunc 'add' did not contain loop with signature matching type dtype ('S32') ('S32') ('S32')
我也尝试过使用纪元日期,但没有奏效。我只是试图绘制日期的价格趋势并将趋势线延伸到日期之后。我知道错误与作为字符串的标签有关。我不确定如何用字符串标签绘制趋势线。我使用的指南有日期标签,所以我不确定我做错了什么。
http://widu.tumblr.com/post/43624347354/matplotlib-trendline
有什么想法吗?
【问题讨论】:
-
哪一行导致了错误?您应该始终发布完整的 Traceback(格式化为代码)
-
我怀疑你可以使用字符串来适应任何东西。您链接到的页面可能不是最可靠的来源。更好地查看各自的问题,例如ths one.
-
那么有没有办法让 matplotlib 将纪元时间转换为标签上的日期,这样我就可以使用纪元值进行绘图,但让它在 x 轴上显示月份值?
标签: python matplotlib charts