- # Python画点或者曲线的轨迹,并保存为动图。
- import matplotlib.pyplot as plt
- import matplotlib.animation as animation
- import numpy as np
- Inputfile = np.loadtxt('SJ.txt') # 滞回曲线存在SJ.txt里
- rows=Inputfile.shape[0]
- if __name__ == "__main__":
- fig = plt.figure()
- xx = []
- yy = []
- yyyy=[]
- for i in range(rows - 1):
- x = Inputfile[i, 0]
- xx.append(x)
- y = Inputfile[i, 1]
- yy.append(y)
- yyy=plt.plot(xx, yy)
- yyyy.append(yyy)
- ani = animation.ArtistAnimation(fig, yyyy, interval=0.000001, repeat_delay=1000)
- ani.save("test3.gif",writer='pillow')
复制代码以2个滞回环为例,结果如下:
(此为gif动图,手机不能观看,可用电脑观看!)
|