python - Animating a Quadmesh from pcolormesh with matplotlib -


as result of full day of trial , error, i'm posting findings else may come across problem.

for last couple days, i've been trying simulate real-time plot of radar data netcdf file work gui i'm building school project. first thing tried simple redrawing of data using 'interactive mode' of matplotlib, follows:

import matplotlib.pylab plt  fig = plt.figure() plt.ion() #interactive mode on in range(2,155): #set number of rows in quadmesh, start @ 2 overlap     plt.hold(true)     print     #please note: use example must compute x, y, , c previously.     #here take slice of data i'm plotting - if real-time     #plot, insert new data plotted here.     temp = plt.pcolormesh(x[i-2:i], y[i-2:i], c[i-2:i])     plt.draw()     plt.pause(.001) #you must use plt.pause or figure freeze   plt.hold(false)        plt.ioff() #interactive mode off 

while technically works, disables zoom functions, pan, , well, everything!

for radar display plot, unacceptable. see solution below.

so started looking matplotlib animation api, hoping find solution. animation did turn out looking for, although use quadmesh object in slices not documented. came with:

import matplotlib.pylab plt matplotlib import animation  fig = plt.figure()  plt.hold(true) #we need prime pump, speak , create quadmesh plt work plt.pcolormesh(x[0:1], y[0:1], c[0:1])  anim = animation.funcanimation(fig, animate, frames = range(2,155), blit = false)  plt.show() plt.hold(false)  def animate( self, i):     plt.title('ray: %.2f'%i)     #this new data inserted plot.     plt.pcolormesh(x[i-2:i], y[i-2:i], c[i-2:i]) 

note blit must false! otherwise yell @ quadmesh object not being 'iterable'.

i don't have access radar yet, haven't been able test against live data streams, static file, has worked great far. while data being plotted, can zoom , pan animation.

good luck own animation/plotting ambitions!


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -