python - Animating Text in Matplotlib Basemap -


i plotting 2d array on matplotlib's basemap , animating through time. having trouble adding in time counter. animation starts @ 0 ut , progresses through 23 ut before starting on @ 0ut. animation works beautifully.

here code:

from netcdf4 import dataset import numpy np import matplotlib.pyplot plt mpl_toolkits.basemap import basemap, addcyclic import matplotlib.animation animation  #load netcdf file variable mar120="c:/users/willevo/desktop/my datasets share/sa120_iono_acc_we.nc"  #grab data new variable fh=dataset(mar120,mode="r")  #assign model variable contents python variables lons=fh.variables['lon'][:] lats=fh.variables['lat'][:] var1=fh.variables['ntd_up'][:]  #specifying time , elevation map ionst=var1[0,18,:,:] details='(0ut, z=2)'  #close netcdf file fh.close()  details='(0ut, z=2)'  # rid of white stripe on map ionst, lons=addcyclic(ionst, lons)  #setting figure attributes fig=plt.figure(figsize=(12,12),facecolor='white')  #map settings m=basemap(llcrnrlon=-180, llcrnrlat=-87.5, urcrnrlon=180, urcrnrlat=87.5,rsphere=6467997, resolution='l', projection='cyl',area_thresh=10000, lat_0=0, lon_0=0)  #creating 2d array of latitude , longitude lon, lat=np.meshgrid(lons, lats) xi, yi=m(lon, lat)  #plotting data onto basemap cs=m.imshow(ionst, interpolation=none, alpha=.8)  #drawing grid lines m.drawparallels(np.arange(-90.,90.,30.),labels=[1,0,0,0],fontsize=10) m.drawmeridians(np.arange(-180.,181.,30.), labels=[0,0,0,1],fontsize=10)  #drawing coast lines m.drawcoastlines()  #color bar cbar=m.colorbar(cs, location='bottom', pad="10%") cbar.set_label(r"ion drag $(cm/s^2)$")  #title preferences plt.title('ion drag @ '+details, size=16)   #function update plots data def updateax1(j):     cs.set_array(var1[j,18,:,:])     return cs,  #animate plot ani1=animation.funcanimation(fig, updateax1, frames=range(24), interval=150, blit=true)  #showing plot plt.show() 

i have tried setting figure text this:

text=figtext(0,0,'sometext') 

and updating in update function this:

def updateax1(j):         text.set_text(str(j))         cs.set_array(var1[j,18,:,:])         return cs, text, 

but causes entire animation stop. have been trying figure out weeks. please lend me genius few seconds! thanks!

simple solution not found anywhere explicitly. change text instance figtext simple ax.text instance , animation works perfectly.


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -