如何修复错误:“matplotlib当前正在使用非GUI后端”

时间:2017-12-29 18:47:22

标签: python animation matplotlib

我希望打印一个在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()

0 个答案:

没有答案