Anaconda3.exe
首先引入需要的python 模块:
其次设置figure的坐标系为极坐标,并设置半径的范围:
然后填充显示阿基米德螺线所需要的数据:
最后发送显示命令,准备显示:
得到最终的示意图:
让我们通过动画来看一下阿基米德螺线的运动轨迹:
简单版本:import matplotlib.pyplot as pltimport numpy as npfrom matplotlib import animationplt.subplot(111, polar=True)plt.ylim([0, 30])N = 4theta = np.arange(0, N * np.pi, np.pi / 100)plt.plot(theta, theta*2, '--')plt.show()
带动画的阿基米德螺线:import matplotlib.pyplot as pltimport numpy as npfrom matplotlib import animationfig = plt.figure()plt.subplot(111, polar=True)plt.ylim([0, 30])line, = plt.plot([], [], '--')def init(): line.set_data([], []) return line,def animate(i): if i!=0: theta = np.arange(0, i * np.pi, np.pi / 100) line.set_data(theta, theta*3) return line,anim = animation.FuncAnimation(fig, animate, init_func=init, frames=8, interval=300, blit=True) plt.show()