PyCharm无法显示动画 [英] PyCharm cannot show animation
问题描述
我正在尝试使用软件包 matplotlib.animation
在PyCharm中绘制动画。但是,PyCharm只在PNG图中显示动画的第一帧。
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.
动画是一个移动的矩形,python版本是2.7.14,代码是此处:
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()
它在终端上运行良好,所以我认为PyCharm出了点问题。那该怎么办?
It runs well in the terminal, so I think there is something wrong with PyCharm. So what can I do?
推荐答案
PyCharm中的科学视图无法处理动画。您必须在设置 |设置中禁用绘图集成。工具| Python科学|在工具窗口中显示图。 PyCharm错误跟踪器中的相应票证: PY-27233 。
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.
这篇关于PyCharm无法显示动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!