在 VS Code 中,可以通过以下步骤来确保动画正确显示:
配置 VS Code 使用适当的绘图后端:
VS Code 中使用 matplotlib 的动画功能,需要配置适当的绘图后端。推荐使用 TkAgg
或者 Qt5Agg
后端。你可以在代码中显式指定:
import matplotlib
matplotlib.use('Qt5Agg') # 或者 'TkAgg'
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.animation import FuncAnimation
# 创建图形和轴
fig