david
david

Reputation: 954

PyCharm cannot show animation

I am trying to use the package matplotlib.animation to draw animation in PyCharm. However, PyCharm only show the first frame of the animation in a PNG figure.

The animation is about a moving rectangle, the python version is 2.7.14 and the code is here:

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

x = [0, 1, 2]
y = [0, 1, 2]
yaw = [0.0, 0.5, 1.3]
fig = plt.figure()
plt.axis('equal')
plt.grid()
ax = fig.add_subplot(111)
ax.set_xlim(-10, 10)
ax.set_ylim(-10, 10)

patch = patches.Rectangle((0, 0), 0, 0, fc='y')

def init():
    ax.add_patch(patch)
    return patch,

def animate(i):
    patch.set_width(1.2)
    patch.set_height(1.0)
    patch.set_xy([x[i], y[i]])
    patch._angle = -np.rad2deg(yaw[i])
    return patch,

anim = animation.FuncAnimation(fig, animate,
                               init_func=init,
                               frames=len(x),
                               interval=500,
                               blit=True)
plt.show()

It runs well in the terminal, so I think there is something wrong with PyCharm. So what can I do?

Upvotes: 1

Views: 4971

Answers (1)

Pavel Karateev
Pavel Karateev

Reputation: 8550

Scientific view in PyCharm can't handle animation, unfortunately. You have to disable plots integration in Settings | Tools | Python Scientific | Show plots in tool window. Corresponding ticket in PyCharm bug tracker: PY-27233.

Upvotes: 8

Related Questions