Quantcast
Channel: WP快站
Viewing all articles
Browse latest Browse all 233

Embedding Matplotlib Animations in Python (google colab notebook)

$
0
0

I am trying to show a gif file in google's colab.research. I was able to save the file in the directory with the following path name /content/BrowniamMotion.gif but I don't know how to show this GIF in my notebook to present.

The code to generate the GIF so far, in case someone can manipulate it not to save the GIF but rather to animate it directly into the google colab file was,

# Other Brownian Motionfrom math import *import numpy as npimport matplotlib.pyplot as pltfrom mpl_toolkits import mplot3dimport matplotlib.animation as animationfig = plt.figure(figsize=(8,6))ax = plt.axes(projection='3d')N=10#val1 = 500x=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.scatter3D(x, y, z, c='r')    return plotanim = animation.FuncAnimation(fig, frame, frames=100, blit=False, repeat=True)anim.save('BrowniamMotion.gif', writer = "pillow", fps=10 )  

Sorry if this question is badly, stated. I am new to Python and using colab research.


Viewing all articles
Browse latest Browse all 233

Trending Articles