![](/img/trans.png)
[英]Why is matplotlib.animation.FuncAnimation producing a blank ouput in a Jupyter notebook?
[英]Matplotlib FuncAnimation not plotting any chart inside Jupyter Notebook
簡單 matplotlib plot。 這是我的代碼
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 筆記本來運行它? 我嘗試使用本機庫,它工作得很好。 這些圖是可見的。
檢查here我看到了同樣的情況。 您可以嘗試在導入 matplotlib 之前使用%matplotlib inline
作為:
%matplotlib inline # this line before importing matplotlib
from matplotlib import pyplot as plt
也就是說,可以使用 JavaScript 顯示 animation。 這類似於 ani.to_html5() 解決方案,只是它不需要任何視頻編解碼器。
from IPython.display import HTML
HTML(a.to_jshtml())
這個答案帶來了更完整的概述......
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.