如何绘制这些方程式?输出为空-只有轴但没有线
# taken from source code output of fitting software
a = -4.8044356996540731E+00
b = -1.7238982381056298E+00
c = 9.7121730188860766E+00
d = 2.0725836239688458E-02
f = -2.3810662793461059E+00
g = -6.8495593999129412E-05
h = 1.7294254445305737E-01
i = 2.6034147965619335E-02
j = -8.6126736653591163E-04
k = 5.8779369562417683E-05
z = a
z += b * x
z += c * y
z += d * pow(x, 2.0)
z += f * pow(y, 2.0)
z += g * pow(x, 3.0)
z += h* pow(y, 3.0)
z += i * x * y
z += j * pow(x, 2.0) * y
z += k * x * pow(y, 2.0)
return z
答案 0 :(得分:4)
您当前正在计算x
和y
的单个值:
>>> import numpy as np
>>> r, a, n, t = 50, 5, 20, 5
>>> x = (r + a * np.sin(n * t * 360 )) * np.cos (t * 360 )
>>> y = (r + a * np.sin(n * t * 360 )) * np.sin (t * 360 )
>>> print(x, y)
-47.22961311822641 6.299155241288046
这意味着matplotlib没有行要绘制。
要绘制一条线,您必须传递两个或多个点,matplotlib才能在它们之间绘制线。
import matplotlib.pyplot as plt
import numpy as np
t = np.linspace(0, 2*np.pi, 100) # create an array of 100 points between 0 and 2*pi
x = np.sin(2*t)
y = np.cos(t)
plt.plot(x, y)
plt.show()
或者您的情况:
t = np.linspace(0, 2*np.pi, 1000)
# removed the factor *360 as numpy's sin/cos works with radians by default
x = (r + a * np.sin(n * t)) * np.cos(t)
y = (r + a * np.sin(n * t)) * np.sin(t)
plt.plot(x, y)
plt.show()
答案 1 :(得分:2)
您正在t=5
处评估函数。您应提供一系列值进行评估。例如,如果将t
变量更改为
t= np.array([0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1])
您将看到一个图形。但是,您可以根据自己的需要定义范围和步骤