我一直在尝试用python绘制蝶形曲线,这是我的代码。
import math
r = np.arange(0, 2, 0.01)
theta = 2 * np.pi * r
r_of_theta=math.exp(np.sin(theta))-2*np.cos(4*theta)+sin((2*theta-np.pi)/24)**5
t_of_theta.astype(int)
ax = plt.subplot(projection='polar')
ax.plot(theta,t,color='blue')
ax.set_rticks([0.5, 1, 1.5, 2])
ax.set_rlabel_position(-22.5)
plt.show()
但我不断收到这个错误
TypeError Traceback (most recent call last)
<ipython-input-66-876098af4358> in <module>()
2 r = np.arange(0, 2, 0.01)
3 theta = 2 * np.pi * r
----> 4 r_of_theta=math.exp(np.sin(theta))-2*np.cos(4*theta)+sin((2*theta-np.pi)/24)**5
5 t_of_theta.astype(int)
6 ax = plt.subplot(projection='polar')
TypeError: only size-1 arrays can be converted to Python scalars
有人可以帮我吗?提前致谢。
看,您有几个输入错误。您应该np.
在任何地方使用。
import numpy as np
import matplotlib.pyplot as plt
r = np.arange(0, 2, 0.01)
theta = 2 * np.pi * r
r_of_theta = []
r_of_theta = np.exp(np.sin(theta[:]))-2*np.cos(4*theta[:])+np.sin((2*theta[:]-np.pi)/24)**5
r_of_theta.astype(int)
ax = plt.subplot(projection='polar')
ax.plot(r_of_theta,color='blue')
ax.set_rticks([0.5, 1, 1.5, 2])
ax.set_rlabel_position(-22.5)
plt.show()
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句