2

I cannot run matplotlib animations using anaconda. I’m trying to run this on Spyder:

import numpy as np
from matplotlib import pyplot as plt
from matplotlib import animation

# First set up the figure, the axis, and the plot element we want to animate
fig = plt.figure()
ax = plt.axes(xlim=(0, 2), ylim=(-2, 2))
line, = ax.plot([], [], lw=2)

# initialization function: plot the background of each frame
def init():
    line.set_data([], [])
    return line,

# animation function. This is called sequentially
def animate(i):
    x = np.linspace(0, 2, 1000)
    y = np.sin(2 * np.pi * (x - 0.01 * i))
    line.set_data(x, y)
    return line,

# call the animator. blit=True means only re-draw the parts that have changed.
anim = animation.FuncAnimation(fig, animate, init_func=init,
        frames=200, interval=20, blit=True)

plt.show()

But it gives me a blank plot. I'm using this directly off of the documentation website as an example and it is not working.

hitzg
  • 12,133
  • 52
  • 54
GlassSeaHorse
  • 429
  • 2
  • 7
  • 14
  • Works perfect for me [link](http://gfycat.com/DependableElatedCivet). I use python 3.4 on Ubuntu 14.04 x64. Maybe its os related issue? – Marcin Jan 06 '15 at 06:10
  • It might be then. I'm running OS X Yosemite 10.10.1 and was using Spyder 2.3.2 to run my code. – GlassSeaHorse Jan 06 '15 at 06:18
  • It must be something else than the code. Your code works without problems. Maybe its python version, matplotlib version, osx issue, .... – Marcin Jan 06 '15 at 06:28

1 Answers1

0

I think you're using Pycharm which have some bug. you need to toggle off scientific mode off in preference->tools->python scientific-> show plots in tool window. and add

%matplotlib qt5

before drawing

Art
  • 2,836
  • 4
  • 17
  • 34
prof_fl
  • 11
  • 2