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()
Mogsdad
  • 44,709
  • 21
  • 151
  • 275
Abhik Banerjee
  • 357
  • 1
  • 6
  • 9
  • there is not an accepted answer on the duplicate thread... – kevinkayaks Jan 19 '19 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. – hoohoo-b May 31 '19 at 07:34

0 Answers0