我想打印一个在Spyder上运行时自动更新的图形。我一直尝试使用matplotlib动画,但是每次要求输入后,它都不会显示图表,而是显示:
matplotlib当前正在使用非GUI后端,因此无法显示该图
我在这里的代码中做错了吗?
import matplotlib.pyplot as plt
import matplotlib.animation as anim
import math
amp=int(input("Please Enter the amplitude-"))
omeg=int(input("Please enter the angular frequency-"))
phdiff=int(input("Please enter the phase difference-"))
t=0
fig=plt.figure()
ax1=fig.add_subplot(111)
def animate(i):
global t
y=amp*math.sin((omeg*t)+phdiff)
fig.clear()
ax1.plot(t,y)
t+=1
animated=anim.FuncAnimation(fig,animate,interval=1000)
fig.show()
Run Code Online (Sandbox Code Playgroud)