Jennie D'Ambroise
Jennie D'Ambroise

Reputation: 111

How to save PyPlot figures to video file in Julia?

I want to do something like the following using a loop and PyPlot to plot in figure windows. My question is how to save the figure windows to a movie file within the loop?

using PyPlot

for k=1:5
  pcolormesh(rand(10,10)) 
  if k==1; colorbar(); end
  # save figure window to movie file here??
  sleep(.5)
end

Upvotes: 3

Views: 1134

Answers (1)

David P. Sanders
David P. Sanders

Reputation: 5325

This is possible by directly using the animation submodule of matplotlib (the underlying Python library that PyPlot.jl wraps). However, it is painful; see e.g. the following notebook (in Spanish):

https://github.com/dpsanders/fisica_computacional/blob/master/como_animar.ipynb

The simplest way, however, seems to be using Plots.jl:

https://github.com/tbreloff/ExamplePlots.jl/blob/master/docs/pyplot_examples.md#functions-adding-data-and-animations.

Upvotes: 2

Related Questions