我在Anaconda3的GUI中使用Python 3,在其中创建带有功能代码的主代码以将输出设置为.ui文件。
下图显示了我的项目的树: Here is the detail of what I having for my project
我具有下图中显示的文件中的数据:.txt file
我在列表中得到的列分别称为FR,HP和EF。我将该信息发送到了最小二乘函数,该函数返回具有系数的x值和y值
现在,我想用处理FR和HP返回x值和y值的一张图绘制数据,并且需要像散布一样包含原始数据FR和HP。 然后,我需要包括处理FR和EF的其他输入,它们也将从绘制原始数据的三次最小二乘函数返回x值和y值。
显然我只能绘制FR和EF,所以我需要一些帮助来绘制FR和PH的结果
这是我的代码:
def plot1(self, xvals, yvals, FR,HP):
self.figure.clf() # clear the figure every time that it runs again
ax = self.figure.add_subplot(111)
ax2 = ax.twinx()
ax.set_title('Pump Head and Efficiency Curves')
ax.plot(xvals, yvals, 'r-')
ax.plot(FR, HP, 'bx') # plotting the original data in blue exes
ax.set_xlabel('Mass Flow Rate [gpm]')
ax.set_ylabel('Head [ft]', color='g')
ax2.set_ylabel('Efficiency [%]', color='b')
ax.legend(['Head Curve Fit', 'Head Data'])
#this I am not sure
# ax2.plot(xvals, yvals, 'g-')
# ax2.plot(FR, EF, 'bo')
ax2.legend(['Efficiency Curve Fit', 'Efficiency Data'])
self.draw()
这段代码给了我这个: Plot from the code that I wrote
代码的目标是得到一个像这样的图: target plot
这也是我用来获取power = 3的三次最小二乘的代码,它返回具有各自系数的xval和yval:
def LeastSquaresData(x, y, power,npoints=500):
a = LeastSquares(x, y, power) # perform the least-squares fit
# calculate points for plotting
minx=min(x);maxx=max(x)
xvals = np.linspace(minx, maxx, npoints) # xvalues for plotting
yvals = np.zeros_like(xvals) # preloaded with zeros .. to start a sum!
#loop an create the yvals
for i in range(len(xvals)):
yvals[i] = Horner(xvals[i],a)
#next i
return xvals, yvals