Instantly share code, notes, and snippets.

# genkuroki/Examples of animations in Julia by PyPlot and matplotlib.animation.ipynb Last active Jun 25, 2017

Julia/Stream diagram for Q(z)=(z^2-1)／z^3
 { "cells": [ { "metadata": {}, "cell_type": "markdown", "source": "# Animations in Julia by PyPlot and matplotlib.animation" }, { "metadata": {}, "cell_type": "markdown", "source": "## Example 1\n\nhttp://intro.syzygy.ca/julia-for-computing/#animation-in-julia" }, { "metadata": { "scrolled": false, "trusted": true }, "cell_type": "code", "source": "using PyPlot\nusing PyCall\n@pyimport matplotlib.animation as anim\n\n#Construct Figure and Plot Data\nfig = figure(\"MyFigure\",figsize=(5,5))\nax = axes(xlim = (0,10),ylim=(0,10))\nglobal line1 = ax[:plot]([],[],\"r-\")[1]\nglobal line2 = ax[:plot]([],[],\"g-\")[1]\nglobal line3 = ax[:plot]([],[],\"b-\")[1]\n\n# Define the init function, which draws the first frame (empty, in this case)\nfunction init()\n global line1\n global line2\n global line3\n line1[:set_data]([],[])\n line2[:set_data]([],[])\n line3[:set_data]([],[])\n return (line1,line2,line3,Union{}) # Union{} is the new word for None\nend\n\n# Animate draws the i-th frame, where i starts at i=0 as in Python.\nfunction animate(i)\n global line1\n global line2\n global line3\n x = (0:i)/10.0\n line1[:set_data](x,x)\n line2[:set_data](1+x,x)\n line3[:set_data](2+x,x)\n return (line1,line2,line3,Union{})\nend\n\n# Create the animation object by calling the Python function FuncAnimaton\nmyanim = anim.FuncAnimation(fig, animate, init_func=init, frames=100, interval=20)\n\n# Convert it to an MP4 movie file and saved on disk in this format.\n#myanim[:save](\"3Lines.mp4\", bitrate=-1, extra_args=[\"-vcodec\", \"libx264\", \"-pix_fmt\", \"yuv420p\"])\nmyanim[:save](\"test1.mp4\", bitrate=-1, extra_args=[\"-vcodec\", \"libx264\", \"-pix_fmt\", \"yuv420p\"])\n \n# Function for creating an embedded video given a filename\nfunction html_video(filename)\n open(filename) do f\n base64_video = base64encode(f)\n \"\"\"