Python Matplotlib FuncAnimation未在Jupyter笔记本内绘制任何图表

Python Matplotlib FuncAnimation未在Jupyter笔记本内绘制任何图表,python,matplotlib,jupyter-notebook,jupyter,Python,Matplotlib,Jupyter Notebook,Jupyter,简单的matplotlib绘图。这是我的密码 from matplotlib import pyplot as plt from matplotlib.animation import FuncAnimation from itertools import count import random x = [] y = [] index=count() def animate(i): x.append(next(index)) y.append(random.randint(0,

简单的matplotlib绘图。这是我的密码

from matplotlib import pyplot as plt
from matplotlib.animation import FuncAnimation
from itertools import count
import random

x = []
y = []
index=count()
def animate(i):
    x.append(next(index))
    y.append(random.randint(0,10))
    plt.plot(x,y)

a = FuncAnimation(plt.gcf(),animate,interval=1000)
plt.tight_layout()
plt.show()
运行上面的代码,我得到

<Figure size 576x396 with 0 Axes>


但没有显示图表。

您是否使用Jupyter笔记本电脑运行它?我尝试使用本地库,效果很好。情节清晰可见

我也看到了同样的情况。在将matplotlib作为以下内容导入之前,是否可以尝试使用
%matplotlib inline

%matplotlib inline # this line before importing matplotlib
from matplotlib import pyplot as plt
也就是说,可以使用JavaScript显示动画。这类似于ani.to_html5()解决方案,只是它不需要任何视频编解码器

from IPython.display import HTML
HTML(a.to_jshtml())

这带来了一个更完整的概述…

您是否使用Jupyter笔记本来运行它?我尝试使用本地库,效果很好。情节清晰可见

我也看到了同样的情况。在将matplotlib作为以下内容导入之前,是否可以尝试使用
%matplotlib inline

%matplotlib inline # this line before importing matplotlib
from matplotlib import pyplot as plt
也就是说,可以使用JavaScript显示动画。这类似于ani.to_html5()解决方案,只是它不需要任何视频编解码器

from IPython.display import HTML
HTML(a.to_jshtml())

这带来了更完整的概述…

是的,我正在使用jupyter笔记本。即使在内联使用%matplotlib之后,我也会得到一个空图形。我认为问题在于动画。如前所述,您需要使用HTML5视频来渲染动画…是的,我使用的是jupyter笔记本。即使在内联使用%matplotlib之后,我也会得到一个空图形。我认为问题在于动画。如前所述,您需要使用HTML5视频渲染动画…如果建议的答案解决了您的问题,您介意选择它作为问题的答案吗?谢谢如果建议的答案解决了你的问题,你介意选择它作为你问题的答案吗?谢谢