6

I want to print a graph that updates itself automatically, when run on Spyder. I keep trying to use the matplotlib animation but every time after asking for inputs, instead of plotting the graph, it just shows:

matplotlib is currently using a non-GUI backend, so cannot show the figure

Am I doing something wrong in the code here?

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()
2
  • there is not an accepted answer on the duplicate thread... Commented Jan 19, 2019 at 16:37
  • 1
    Try: matplotlib.use('module://ipykernel.pylab.backend_inline') to use the same matplotlib backend as Jupyter uses. In a Jupyter notebook, run %matplotlib inline, matplotlib.get_backend() to confirm the backend used. Commented May 31, 2019 at 7:34

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.