DKRZ PyNGL example streamline plot#
Example:
from __future__ import print_function
import Ngl,Nio
#-----------------------------------------------------------------------
#-- Function: main
#-----------------------------------------------------------------------
def main():
#-- open a file and read variables
f = Nio.open_file("rectilinear_grid_2D.nc", "r")
u = f.variables["u10"]
v = f.variables["v10"]
ua = f.variables["u10"][0,:,:]
va = f.variables["v10"][0,:,:]
lat = f.variables["lat"]
lon = f.variables["lon"]
nlon = len(lon)
nlat = len(lat)
#-- open a workstation
wks = Ngl.open_wks("png","plot_TRANS_streamline_py")
#-- resource settings
stres = Ngl.Resources()
stres.nglFrame = False
stres.vfXArray = lon[::3]
stres.vfYArray = lat[::3]
stres.mpFillOn = True
stres.mpOceanFillColor = "Transparent"
stres.mpLandFillColor = "Gray90"
stres.mpInlandWaterFillColor = "Gray90"
#-- create the plot, use every 3rd data value
plot = Ngl.streamline_map(wks,ua[::3,::3],va[::3,::3],stres)
#-- write variable long_name and units to the plot
txres = Ngl.Resources()
txres.txFontHeightF = 0.014
Ngl.text_ndc(wks,f.variables["u10"].attributes['long_name'],0.16,0.76,txres)
Ngl.text_ndc(wks,f.variables["u10"].attributes['units'], 0.95,0.76,txres)
#-- advance the frame
Ngl.frame(wks)
Ngl.end()
if __name__ == '__main__':
main()
Result: