from matplotlib import pyplot as plt import numpy as np def plt_draw_dynamic(x, y): for i in range(x.shape[0]): plt.pause(0.001) plt.cla() plt.xlim((-200, 200)) plt.ylim((-200, 200)) plt.plot(x[:i], y[:i]) plt.draw() def draw_polar_rose(): """ 花瓣曲线,https://zh.wikipedia.org/wiki/%E6%9E%81%E5%9D%90%E6%A0%87%E7%B3%BB """ theta = np.arange(-np.pi, np.pi, 0.001) a = 10 # 当k是偶数时曲线将是2k个花瓣,如果k为非整数,将产生圆盘状图形,且花瓣数也为非整数 k = 15.5 r = a * np.cos(k * theta) x = r * np.cos(theta) y = r * np.sin(theta) plt_draw_dynamic(x, y) # plt.plot(x, y) # plt.show() def draw_ajmd_curve(): """ 阿基米德螺线, 改变参数a将改变螺线形状,b控制螺线间距离,通常其为常量。 阿基米德螺线有两条螺线,一条θ>0,另一条θ<0。两条螺线在极点处平滑地连接。把其中一条翻转 90°/270°得到其镜像,就是另一条螺线。 """ theta = np.arange(0, 6 * np.pi, 0.001*6*np.pi) a = 0.1 b = 10 r = a + b * theta x = r * np.cos(theta) y = r * np.sin(theta) plt_draw_dynamic(x, y) # plt.plot(x, y) # plt.show() if __name__ == '__main__': draw_ajmd_curve()
标签:阿基米德,draw,plt,200,Python,螺线,np,theta From: https://www.cnblogs.com/lzqdeboke/p/17802419.html