-
-
Notifications
You must be signed in to change notification settings - Fork 408
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Displaying videos in IJulia? #107
Comments
Almost, for now display as HTML and base 64 encode in URL, as IPython does. Or you can try to prepend 'files/' to URL. There is not much more IJulia can do about arbitrary mime type. Fix is on its way on python side. Envoyé de mon iPhone
|
Thanks for the tip. Posting the code that worked for me here in case someone later on might find it useful. The last two lines in my example should be replaced with: # If matplotlib complains, ensure that
# a) ffmpeg is installed with libx264 support, and
# b) matplotlib is built with ffmpeg support enabled
ani[:save]("noise.mp4", extra_args=["-vcodec", "libx264", "-pix_fmt", "yuv420p"])
display("text/html", string("""<video autoplay controls><source src="data:video/x-m4v;base64,""",
base64(open(readbytes,"noise.mp4")),"""" type="video/mp4"></video>""")) |
Thanks @jiahao for this thread and your final post. It helped me recreate the first example in this excellent blog on IPython notebook animation: I am posting the code below as others might find it useful. using PyCall
using PyPlot
@pyimport matplotlib.animation as anim# First set up the figure, the axis, and the plot element we want to animate
fig = figure()
ax = plt.axes(xlim=(0, 2), ylim=(-2, 2))
global line = ax[:plot]([], [], lw=2)[1]
# initialization function: plot the background of each frame
function init()
global line
line[:set_data]([], [])
return (line,None)
end
# animation function. This is called sequentially
function animate(i)
x = linspace(0, 2, 1000)
y = sin(2 * pi * (x - 0.01 * i))
global line
line[:set_data](x, y)
return (line,None)
end
# call the animator. blit=True means only re-draw the parts that have changed.
myanim = anim.FuncAnimation(fig, animate, init_func=init,
frames=100, interval=20, blit=true)
myanim[:save]("/tmp/sinplot.mp4", extra_args=["-vcodec", "libx264", "-pix_fmt", "yuv420p"])
# call our new function to display the animation
display("text/html", string("""<video autoplay controls><source src="data:video/x-m4v;base64,""",
base64(open(readbytes,"/tmp/sinplot.mp4")),"""" type="video/mp4"></video>""")) |
@mbeltagy Thanks for the nice approach. Any ideas how to extend this to animate (many points) using different colors? |
Hi, I am also trying to animate a simulation using Julia. I would like to try to use the example given in matplotlib for dynamic image animation like here:
(taken from http://matplotlib.org/examples/animation/dynamic_image2.html) Is there an equivalent way to make it in Julia? |
Adapting the above, this works though the loop is a little slow:
|
@JobJob - Thanks for the guidance. I have some problem in using the code, it tries to install matplotlib, and then exit with importerror - http://dpaste.com/0PB2GKV. Someone knows what could be the problem? |
I am interested in using
matplotlib.animation
to generate animations embedded in IJulia notebooks. However, my first attempt to translate a simplematplotlb
into Julia code did not work:Next, I tried rendering the animation to a video file and loading it in IJulia. Using
display("video/mp4",...)
ordisplay("video/mpeg",...)
did not work. But embedding the HTML video tag almost worked...This code renders an empty box and video playback controls, but the controls don't do anything, nor is a video displayed.
Am I on the right track to get embedded animations?
The text was updated successfully, but these errors were encountered: