【问题标题】:Animations in PythonPython中的动画
【发布时间】:2022-10-07 01:00:28
【问题描述】:

我在 vs 代码中运行这个动画代码示例,但动画没有在代码中使用。我可以在 vs code 中安装扩展吗?

from matplotlib import pyplot as plt
from matplotlib.animation import FuncAnimation
import random
import numpy as np

x = []
y = []
colors = []
fig = plt.figure(figsize=(7,5))

def animation_func(i):
    x.append(random.randint(0,100))
    y.append(random.randint(0,100))
    colors.append(np.random.rand(1))
    area = random.randint(0,30) * random.randint(0,30)
    plt.xlim(0,100)
    plt.ylim(0,100)
    plt.scatter(x, y, c = colors, s = area, alpha = 0.5)

animation = FuncAnimation(fig, animation_func,
                        interval = 100)
plt.show()

    标签: python data-science


    【解决方案1】:

    我在 PyCharm 中使用包 Matplotlib、numpy 和 pyqt5 运行代码。动画在此设置中有效。

    确保在您的环境中正确安装了这些软件包。我强烈建议你使用PyCharm 而不是 VsCode。

    【讨论】:

      猜你喜欢
      • 2021-04-02
      • 2018-05-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-15
      • 2020-10-28
      • 2021-03-30
      • 2017-06-22
      相关资源
      最近更新 更多