Professional Documents
Culture Documents
# 起点,终点,粗细,n11(1-实线,2-虚线,3-点画线
# 函数, x-起点,x-终点,粗细,n11(1-实线,2-虚线,3-点画线
n=30
XX=[0]*n; YY=[0]*n
Dx=(x22-x11)/(n-1)
for i in range(n):
XX[i]=x11+Dx*i
YY[i]=FF.subs(x,XX[i])
lines = plt.plot(XX, YY)
if n11==1:
plt.setp(lines, color='k', linewidth=k11,
linestyle='-')
if n11==2:
plt.setp(lines, color='k', linewidth=k11,
linestyle='--')
if n11 == 3:
plt.setp(lines, color='k', linewidth=k11,
linestyle='-.')
if n22==2:
n,HP = np.shape(XY)
for i in range(n):
plt_circle(0.08, XY[i,0], XY[i,1], 1, 1)
x1=XY[i, 0]+0.25; y1=XY[i,1]-0.3
str2="("+str(XY[i,0])+","+str(XY[i,1])+")"
plt_word(x1, y1, str2)
return
def plt_circle(r, x11, y11, k11,n11): #画圆
# r 半径, x,y-圆心坐标,粗细,n11(1-实线,2-虚线,3-点画
线
n=50
XX=[0]*(n+1); YY=[0]*(n+1)
Dx=2*pi/n
for i in range(n+1):
theta=Dx*i
XX[i]=x11+r*cos(theta)
YY[i] = y11 + r * sin(theta)
lines = plt.plot(XX, YY)
if n11==1:
plt.setp(lines, color='k', linewidth=k11,
linestyle='-')
if n11==2:
plt.setp(lines, color='k', linewidth=k11,
linestyle='--')
if n11 == 3:
plt.setp(lines, color='k', linewidth=k11,
linestyle='-.')
return
def plt_word(x1,y1,str2):
# str1 = '%s' % str2
# str2 = str1.replace("**","^^",8)
# str2 = str2.replace("**", "", 8)
plt.text(x1,y1,"$%s$" % str2, size=8)
return
randomnuml=random.randint(1000,9999)
txtfile=str(randomnuml)+".txt" #文件名
f2=open(txtfile,'w')
x=symbols('x')
n1=11; m1=6
[XY,]=form_data(n1)
[A,F]=form_eq(m1)
[a,f]=solve_f()
plot_curve(f,XY)
f2.write("\n F= %s" %f)
输出结果:
F= 0.000783498891058911*x**5 - 0.0292692097439593*x**4 +
0.358012485011466*x**3 - 1.70348356094871*x**2 +
2.61377019220427*x - 0.092440138049295