matplotlib 绘制动图

matplotlib 绘制动图

    • 代码
    • 效果
    • 未完待续....

代码

	import matplotlib.pyplot as plt
	from matplotlib import animation
	import numpy as np
	plt.rcParams['font.sans-serif'] = ['SimHei'] # 步骤一(替换sans-serif字体)
	plt.rcParams['axes.unicode_minus'] = False   # 步骤二(解决坐标轴负数的负号显示问题)
	
	fig,ax1 = plt.subplots()
	
	x = np.arange(0,2*np.pi,0.01)
	line, = ax1.plot(x,np.sin(x))
	
	def animate(i):
	    line.set_ydata(np.sin(x+i/100))
	    return line,
	
	def init():
	    line.set_ydata(np.sin(x))
	    return line,
	
	ani = animation.FuncAnimation(fig=fig,func=animate,frames=100,init_func=init,interval=20,blit=False)
	
	
	
	
	plt.show()

效果

matplotlib 绘制动图_第1张图片

未完待续…

你可能感兴趣的:(matplotlib,python,python)