Recipe: python program example1: Difference between revisions

From GEOS-5
Jump to navigation Jump to search
Created page with "<syntaxhighlight lang="python"> import matplotlib.pyplot as plt import CSnative def main() : # The subscript starts with 0 in python # User should specify the time, l..."
 
No edit summary
 
Line 11: Line 11:
   Level=0
   Level=0
   var='T'
   var='T'
   filename = 'HU_getc180forweyium_c180.geosgcm_prog.20000414_2200z.nc4'
   #filename = 'HU_getc180forweyium_c180.geosgcm_prog.20000414_2200z.nc4'
   filename = 'TEST7.geosgcm_prog.20000415_0000z.nc4'
   filename = 'TEST7.geosgcm_prog.20000415_0000z.nc4'



Latest revision as of 18:51, 6 March 2017

import matplotlib.pyplot as plt

import CSnative

def main() :

   # The subscript starts with 0 in python
   # User should specify the time, level, fieldname (var), and filename
   Time=0
   Level=0
   var='T'
   #filename = 'HU_getc180forweyium_c180.geosgcm_prog.20000414_2200z.nc4'
   filename = 'TEST7.geosgcm_prog.20000415_0000z.nc4'

   lons,lats,data = CSnative.get_csdata(filename, var, Time, Level);
   # color map plot
   plt.figure()
   plt.tripcolor(lons,lats,data.T,vmin=data.min(), vmax=data.max())
   plt.axis([lons.min(), lons.max(), lats.min(), lats.max()])
   plt.colorbar()
   plt.draw()
   plt.show(block=False)
   # plt.savefig('T1.png')

   # contour plot
   plt.figure()
   plt.tricontour(lons,lats,data.T, 20, linewidths=0.5,cmap=plt.cm.rainbow )
   plt.axis([lons.min(), lons.max(), lats.min(), lats.max()])
   plt.colorbar()
   plt.draw()
   plt.show()


if __name__ == '__main__' :
   main()