我正在尝试在Google的colab.research中显示一个gif文件。我能够使用以下路径名将文件保存在目录中,/content/BrowniamMotion.gif
但是我不知道如何在笔记本中显示此GIF。
到目前为止,如果有人可以操纵它而不是保存GIF而是直接将其设置为google colab文件的动画,那么生成GIF的代码是,
# Other Brownian Motion
from math import *
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits import mplot3d
import matplotlib.animation as animation
fig = plt.figure(figsize=(8,6))
ax = plt.axes(projection='3d')
N=10
#val1 = 500
x=500*np.random.random(N)
y=500*np.random.random(N)
z=500*np.random.random(N)
def frame(w):
ax.clear()
global x,y,z
x=x+np.random.normal(loc=0.0,scale=50.0,size=10)
y=y+np.random.normal(loc=0.0,scale=50.0,size=10)
z=z+np.random.normal(loc=0.0,scale=50.0,size=10)
plt.title("Brownian Motion")
ax.set_xlabel('X(t)')
ax.set_xlim3d(-500.0,500.0)
ax.set_ylabel('Y(t)')
ax.set_ylim3d(-500.0,500.0)
ax.set_zlabel('Z(t)')
ax.set_zlim3d(-500.0,500.0)
plot=ax.scatter
3D(x, y, z, c='r')
return plot
anim = animation.FuncAnimation(fig, frame, frames=100, blit=False, repeat=True)
anim.save('BrowniamMotion.gif', writer = "pillow", fps=10 )
很抱歉,这个问题很严重。我是Python的新手,正在从事colab研究。
对于Colab,最简单的方法是使用“ jshtml”来显示matplotlib动画。
您需要使用
from matplotlib import rc
rc('animation', html='jshtml')
然后,只需键入您的动画对象。它将显示自己
anim
这是您的代码的可行协作库。
它有一个滑块,您可以在任何时间来回运行。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句