Skip to main content

Posts

Showing posts with the label matplotlib

Animations with matplotlib

For some reason this wasn't overly clear in the documentation, but a simple way to make an animation using the default backend in matplotlib is something like this: from numpy import random , array , arange import matplotlib.pyplot as plt plt . ion () print "starting" x = arange ( 100 ) y = 2 * random . rand ( 100 ) line , = plt . plot ( x , y , 'd-' ) for i in arange ( 1 , 200 ): y = y + random . rand ( 100 ) - 0.500000 line . set_data ( x , y ) ax = line . get_axes () ax . relim () ax . autoscale_view () plt . draw () # redraw the canvas plt . show ()

Spyder

Enter the new matlab contender, Spyder: This would have been pretty handy over the last summer! All the pylab, scipy and numpy docs. The matplotlib integration is key. Eventually it would be awesome to see pydb and stepping through python scripts like you can for m files in matlab. But this is a huge step in the right direction! This is also my first post from Windows, good to see that Python(x,y) has been coming along nicely since I last looked at it. I will see how this Pydee (renamed to Spyder) goes on all three platforms that I now use.

Matplotlib in Django

The official django tutorial is very good, it stops short of displaying data with matplotlib - which could be very handy for dsp or automated testing. This is an extension to the tutorial. So first you must do the official tutorial! Complete the tutorial (as of writing this up to part 4). Adding an image to a view To start with we will take a static image from the hard drive and display it on the polls index page. Usually if it really is a static image this would be managed by the webserver eg apache. For introduction purposes we will get django to serve the static image. To do this we first need to change the template. Change the template At the moment poll_list.html probably looks something like this: <h1>Django test app - Polls</h1> {% if object_list %} <ul> {% for object in object_list %} <li><a href="/polls/{{object.id}}">{{ object.question }}</a></li> {% endfor %} </ul> {% else %} <p>No polls...