4

These days I've been trying to create a webpage on which one can watch a dynamic plotting demo. I'm using Django to construct the webpage, and recently have learned that matplotlib.animation can do such kind of job. I wonder whether it's possible to use this API, matplitlib.animation, while building the webpage using Django. (I tried to do it using 'HttpResponse' but only to fail.) If there is any other way to do this, please let me know. Thanks in advance.

  • Can you specify what exactly you mean by "dynamic plotting demo"? Is this a picture that you want matplotlib to generate, or something that the user can interact with? – Geotob Jan 19 '15 at 04:34
  • The user provides the model parameter, then the plot evolves according to Bayesian updating rule. – Joonsuk Park Jan 19 '15 at 04:35
  • another vote for mathplotlib have used it with django and flask – lxx Jan 19 '15 at 04:36
  • You could use [this example](http://wiki.scipy.org/Cookbook/Matplotlib/Django) to generate images based on an AJAX call and render them in the browser. Done this before, works great, but not sure if that's what you're after. – Geotob Jan 19 '15 at 04:40
  • so far I have been able to render a graph, I am trying to animate it as well. Mine is similar to this: http://wiki.scipy.org/Cookbook/Matplotlib/Django but I have found this for animation: http://matplotlib.org/1.4.2/examples/animation/basic_example.html if I am able to transfer rendering a picture to an animation. I'll post what I did. –  Feb 13 '15 at 18:47

1 Answers1

0

You need to write the animation to disk and then serve it up via some static interface. Here is an idea of how to accomplish it:

Make your webserver point /animations to /var/www/animations

Save your animations in that folder (You can save mp4 and use HTML5 but if you want to save a GIF this SO has information on what is needed. You could use a model to hold initializing parameters and a hash of those (which would make a decent filename).

Render it in your templates with a regular img tag (or video tag if you use mp4).

Community
  • 1
  • 1