小编Abh*_*jee的帖子

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

我想打印一个在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)

python animation matplotlib

5
推荐指数
0
解决办法
1万
查看次数

标签 统计

animation ×1

matplotlib ×1

python ×1