我的代码在我的图表中生成了一个 polyfit,但我希望这个拟合总是通过零,我该怎么做?
import pylab as pl
import numpy as np
y=(abs((UX2-UY2)+(2*UXY)))
a=np.mean(y)
y=y-a
x=(abs((X2-Y2)+(2*XY)))
b=np.mean(x)
x=x-b
ax=pl.subplot(1,4,4) #plot XY
fit=pl.polyfit(x,y,1)
slope4, fit_fn=pl.poly1d(fit)
print slope4
fit_fn=pl.poly1d(fit)
x_min=-2
x_max=5
n=10000
x_fit = pl.linspace(x_min, x_max, n)
y_fit = fit_fn(x_fit)
q=z=[-2,5]
scat=pl.plot(x,y, 'o', x_fit,y_fit, '-r', z, q, 'g' )