PyNGL example map settings#

Software requirements:

  • Python 2 or 3

  • PyNGL 1.6.1

Run the map example script:

python PyNGL_map_settings.py

Script PyNGL_map_settings.py:

'''
DKRZ PyNGL Script: PyNGL_map_settings.py

Description:  plot a simple USA map

 - show the use of map resources

09.02.21 meier-fleischer(at)dkrz.de
'''
import Ngl

#-----------------------------------------------------------------------
#-- Function: main
#-----------------------------------------------------------------------
def main():

    #-- open a workstation
    wkres = Ngl.Resources() #-- generate an resources object for workstation
    wkres.wkWidth = 1024 #-- width of workstation
    wkres.wkHeight = 1024 #-- height of workstation
    wks_type = "png" #-- output type of workstation
    wks = Ngl.open_wks(wks_type,"Py_map_settings") #-- open workstation

    #-- set map resources
    res = Ngl.Resources() #-- generate an res object for plot
    res.nglMaximize = True #-- maximize plot in frame
    res.tiMainString = "USA" #-- title string

    #-- map resources
    res.mpDataSetName = "Earth..4" #-- set map data base version
    res.mpDataBaseVersion = "MediumRes" #-- MediumRes = Ncarg4_1
    res.mpGeophysicalLineThicknessF = 2. #-- line thickness of coastal borders
    res.mpFillOn = True #-- turn on fill for map areas.
    res.mpLandFillColor = "LightGray" #-- fill color land
    res.mpOceanFillColor = "lightblue" #-- fill color ocean
    res.mpInlandWaterFillColor = "lightblue" #-- fill color inland water
    res.mpOutlineOn = True #-- turn on map outlines
    res.mpOutlineBoundarySets = "national" #-- "national"
    res.mpOutlineSpecifiers = "conterminous us : states" #-- plot state boundaries
    res.mpGridLatSpacingF = 5. #-- grid spacing for latitude
    res.mpGridLonSpacingF = 5. #-- grid spacing for longitude
    res.mpGridLineDashPattern = 7 #-- dash pattern for grid lines
    res.mpLimitMode = "LatLon" #-- limit map via lat/lon
    res.mpMinLatF = 20. #-- minimum latitude
    res.mpMaxLatF = 50. #-- maximum latitude
    res.mpMinLonF = -130. #-- minimum longitude
    res.mpMaxLonF = -65. #-- maximum longitude

    res.pmTickMarkDisplayMode = "Always" #-- turn on map tickmarks

    #-- draw the map
    map = Ngl.map(wks,res)

    #-- done
    Ngl.end()

 if __name__ == '__main__':
     main()

Result:

PyNGL map settings w400