相关文章推荐
呐喊的键盘  ·  Java HttpClient ...·  1 年前    · 
import matplotlib.pyplot as plt import matplotlib as mpl from matplotlib.animation import FuncAnimation # mpl.use("Qt5Agg") mpl.rcParams['font.sans-serif'] = ['SimHei'] mpl.rcParams['font.serif'] = ['SimHei'] mpl.rcParams['axes.unicode_minus'] = False # 解决保存图像是负号'-'显示为方块的问题,或者转换负号为字符串 fig, ax = plt.subplots(1, 1) x = np.linspace(0, 2 * np.pi, 5000) y = np.exp(-x) * np.cos(2 * np.pi * x) line, = ax.plot(x, y, color="cornflowerblue", lw=3) ax.set_ylim(-1.0, 1.0) # to clear current frame def init(): line.set_ydata([np.nan] * len(x)) return line, # to update the data def animate(data): line.set_ydata(np.exp(-x) * np.cos(2 * np.pi * x + float(data) / 100)) return line, # to call class FuncAnimation which connects animate and init ani = FuncAnimation(fig, animate, init_func=init, frames=200, interval=2, blit=True) # to save the animation ani.save("movie.mp4", fps=20, writer="ffmpeg") plt.show()

下面展示其中的4帧结果

作     者 ice

个性签名:我与春风皆过客,你携秋水揽星河

---------------------------------------------------------

如果觉得这篇文章对你有小小的帮助的话,记得在右下角点个 “推荐” 哦!

转载请保留原文链接及作者。