gpt4 book ai didi

python - PyCharm无法显示动画

转载 作者:行者123 更新时间:2023-11-30 22:16:23 26 4
gpt4 key购买 nike

我正在尝试使用包 matplotlib.animation 在 PyCharm 中绘制动画。但是,PyCharm 仅以 PNG 图形显示动画的第一帧。

动画是关于一个移动的矩形,python版本是2.7.14,代码在这里:

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有问题。那我能做什么呢?

最佳答案

不幸的是,PyCharm 中的科学 View 无法处理动画。您必须在设置 | 中禁用绘图集成。工具| Python 科学 |在工具窗口中显示绘图。 PyCharm bug tracker 中的相应票证:PY-27233 .

关于python - PyCharm无法显示动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49963666/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com