예제 #1
0
    def contour_map(self):
        params_dict = self.params_dict

        scala_figure = params_dict.pop('scala_figure')
        lon_axis_value, lat_axis_value = params_dict.pop(
            'location', default='93x17').split("x")

        resource = create_or_update_resource(params_dict)
        Ngl.add_text(self.workstation, self.plot, scala_figure, lon_axis_value,
                     lat_axis_value, resource)
예제 #2
0
파일: xy3.py 프로젝트: zhishang80/pyngl
def add_highlights(wks,plot,xmin,xmax,ymin,ymax,title):
  nboxes = 10
  xbox   = Ngl.fspan(xmin,xmax,nboxes)
  ybox   = [ymin,ymin,ymax,ymax,ymin]
  nboxes = xbox.shape[0]-1

#---Resources for filled purple boxes.
  gnres                 = Ngl.Resources()
  gnres.gsFillColor     = "goldenrod" # "MediumPurple1"
  gnres.gsFillOpacityF  = 0.15

  id = []
  for n in range(0,nboxes-1,2):
    id.append(Ngl.add_polygon(wks,plot,\
              [xbox[n],xbox[n+1],xbox[n+1],xbox[n],xbox[n]],\
              ybox,gnres))


#---Resources to outline box of interest
  lnres                  = Ngl.Resources()
  lnres.gsLineThicknessF = 3.0
  border = Ngl.add_polyline(wks,plot,[xmin,xmax,xmax,xmin,xmin],\
                                      [ymin,ymin,ymax,ymax,ymin],lnres)

  txres                 = Ngl.Resources()
  txres.txFontHeightF   = 0.022
  txres.txFont          = "Helvetica-Bold"
  txres.txJust          = "TopCenter"
  text = Ngl.add_text(wks,plot,title,(xmin+xmax)/2.,ymax-0.05,txres)

  return([id,border,text])
예제 #3
0
    def contour_map(self):
        params_dict = self.params_dict
        color_levels = self.color_levels
        cn_fill_colors = np.arange(0, len(color_levels), 1)

        # 1.绘制南海底板
        south_sea_baseboard = params_dict.pop('south_sea_baseboard')
        south_sea_baseboard['cnLevels'] = color_levels
        south_sea_baseboard['cnFillColors'] = cn_fill_colors
        resource = create_or_update_resource(params_dict=south_sea_baseboard)
        south_sea_plot = Ngl.contour_map(self.workstation, self.input_data,
                                         resource)

        # 2.绘制南海相关地理线
        south_sea_geoline = params_dict.pop('south_sea_geoline')  # 多级
        for key, params_dict in south_sea_geoline.items():
            file_name = params_dict.pop('file_name')
            type = params_dict.pop('type')
            shape = Nio.open_file(shape_file_path + file_name, "r")
            lon = np.ravel(shape.variables["x"][:])
            lat = np.ravel(shape.variables["y"][:])
            params_dict['gsSegments'] = shape.variables["segments"][:, 0]
            resource = create_or_update_resource(params_dict=params_dict)
            # 2.绘制曲线图
            if type == 'polyline':
                Ngl.add_polyline(self.workstation, south_sea_plot, lon, lat,
                                 resource)
            else:
                pass  #polygon/point 处理待定

        # 3. 南海加比例尺
        south_sea_scale = params_dict.pop('south_sea_scale')
        scala_figure = south_sea_scale.pop('scala_figure')
        x, y = south_sea_scale.pop('location').split('x')
        resource = create_or_update_resource(params_dict=south_sea_scale)
        Ngl.add_text(self.workstation, south_sea_plot, scala_figure, x, y,
                     resource)

        # 4.南海放在中国的位置
        south_sea_location = params_dict.pop('south_sea_location')
        resource = create_or_update_resource(params_dict=south_sea_location)
        Ngl.add_annotation(self.plot, south_sea_plot, resource)
예제 #4
0
def hilo_valplot(lons, lats, highs, lows, cfg):
    """
    Special case of having a value plot with a high and low value to 
    plot, which is common for some climate applications
    """
    tmpfp = tempfile.mktemp()

    cmap = numpy.array([[1., 1., 1.], [0., 0., 0.], [1., 0., 0.], \
                    [0., 0., 1.], [0., 1., 0.]], 'f')

    rlist = Ngl.Resources()
    rlist.wkColorMap = cmap
    #rlist.wkOrientation = "landscape"
    wks = Ngl.open_wks("ps", tmpfp, rlist)

    res = iowa()
    res.mpOutlineDrawOrder = "PreDraw"
    plot = Ngl.map(wks, res)
    for key in cfg.keys():
        if key == 'wkColorMap' or key[0] == "_":
            continue
        setattr(res, key, cfg[key])

    txres              = Ngl.Resources()
    txres.txFontHeightF = 0.016
    txres.txFontColor   = "red"
    txres.txJust        = "BottomRight"
    for i in range(len(lons)):
        Ngl.add_text(wks, plot, cfg["_format"] % highs[i], 
                      lons[i], lats[i],txres)

    txres              = Ngl.Resources()
    txres.txFontHeightF = 0.016
    txres.txFontColor   = "blue"
    txres.txJust        = "TopRight"
    for i in range(len(lons)):
        Ngl.add_text(wks, plot, cfg["_format"] % lows[i], 
                      lons[i], lats[i],txres)

    if cfg.has_key("_labels"):
        txres               = Ngl.Resources()
        txres.txFontHeightF = 0.008
        txres.txJust        = "CenterLeft"
        txres.txFontColor   = 1
        for i in range(len(lons)):
            Ngl.add_text(wks, plot, cfg["_labels"][i], 
                     lons[i], lats[i],txres)

    watermark(wks)
    manual_title(wks, cfg)
    vpbox(wks)
    Ngl.draw(plot)
    Ngl.frame(wks)
    del wks

    return tmpfp
예제 #5
0
파일: traj1.py 프로젝트: zhishang80/pyngl
def add_labelbar(wks,map,cmap):
  gsres = Ngl.Resources()  # Line resources.

  delta_lon = 4.0
  delta_lat = 2.1
  start_lon = -68.
  start_lat = -58.
  txres = Ngl.Resources()          # For labeling the label bar.
  txres.txFontHeightF = 0.015
  gid = []
  lid = []
  tid = []
  for i in range(4,14,1):
    lon0 = start_lon+(i-4)*delta_lon
    lon1 = lon0+delta_lon
    lat0 = start_lat
    lat1 = start_lat+delta_lat
    lons = [lon0,lon1,lon1,lon0,lon0]
    lats = [lat0,lat0,lat1,lat1,lat0]
    gsres.gsFillColor = cmap[i-4]    # Change fill color.
    gid.append(Ngl.add_polygon(wks,map,lons,lats,gsres))
    lid.append(Ngl.add_polyline(wks,map,lons,lats,gsres))
    if (i == 4):
      tid.append(Ngl.add_text(wks,map,"34.55",lon0,lat0-delta_lat,txres))
    elif(i == 6):
      tid.append(Ngl.add_text(wks,map,"34.61",lon0,lat0-delta_lat,txres))
    elif(i == 8):
      tid.append(Ngl.add_text(wks,map,"34.67",lon0,lat0-delta_lat,txres))
    elif(i == 10):
      tid.append(Ngl.add_text(wks,map,"34.73",lon0,lat0-delta_lat,txres))
    elif(i == 12):
      tid.append(Ngl.add_text(wks,map,"34.79",lon0,lat0-delta_lat,txres))
    else:
      tid.append(Ngl.add_text(wks,map,"34.85",start_lon+10*delta_lon,lat0-delta_lat,txres))
  
  return
예제 #6
0
def plot_power(Pow, symmetry=("symm"), source="", var1="", plotpath="./", flim=0.5, nWavePlt=20, cmin=0.05, cmax=0.55,
               cspc=0.05, plotxy=[1, 1], N=[1, 2]):

    dims = Pow.shape
    nplot = dims[0]

    FillMode = "AreaFill"

    # text labels
    abc = list(string.ascii_lowercase)

    # plot resources
    wkstype = "png"
    wks = ngl.open_wks(wkstype, plotpath + "SpaceTimePower_" + source + var1)
    plots = []

    # coherence2 plot resources
    res = coh_resources(cmin, cmax, cspc, FillMode, flim, nWavePlt)
    # phase arrow resources
    resA = phase_resources(flim, nWavePlt)

    # dispersion curve resources
    dcres = ngl.Resources()
    dcres.gsLineThicknessF = 2.0
    dcres.gsLineDashPattern = 0

    # text box resources
    txres = ngl.Resources()
    txres.txPerimOn = True
    txres.txFontHeightF = 0.013
    txres.txBackgroundFillColor = "Background"

    # panel plot resources
    resP = panel_resources(nplot, abc)

    # plot contours and phase arrows
    pp = 0
    while pp < nplot:
        if nplot == 1:
            coh2 = Pow
        else:
            coh2 = Pow[pp, :, :]
        if len(symmetry) == nplot:
            Symmetry = symmetry[pp]
        else:
            Symmetry = symmetry

        res.tiMainString = source + "    log10( Power(" + var1 + "))           " + Symmetry
        plot = ngl.contour(wks, coh2, res)

        (matsuno_names, textlabels, textlocsX, textlocsY) = text_labels(Symmetry)
        nlabel = len(textlocsX)

        # generate matsuno mode dispersion curves
        if Symmetry == "midlat":
            He = [3000, 7000, 10000]
            matsuno_modes = mp.matsuno_modes_wk_bg(he=He, n=N, latitude=0., max_wn=nWavePlt, n_wn=500, u=25)
        else:
            He = [12, 25, 50]
            matsuno_modes = mp.matsuno_modes_wk(he=He, n=N, latitude=0., max_wn=nWavePlt, n_wn=500)

        # add polylines for dispersion curves
        for he in matsuno_modes:
            df = matsuno_modes[he]
            wn = df.index.values
            for wavename in df:
                for matsuno_name in matsuno_names:
                    if wavename == (matsuno_name + str(he) + "m)"):
                        wave = df[wavename].values
                        wnwave = wn[~np.isnan(wave)]
                        wave = wave[~np.isnan(wave)]
                        ngl.add_polyline(wks, plot, wnwave, wave, dcres)

        # add text boxes
        ll = 0
        while ll < nlabel:
            ngl.add_text(wks, plot, textlabels[ll], textlocsX[ll], textlocsY[ll], txres)
            ll += 1

        plots.append(plot)
        pp += 1

        # panel plots
    ngl.panel(wks, plots, plotxy, resP)
    ngl.delete_wks(wks)
    #ngl.end()

    return
예제 #7
0
파일: hdf1.py 프로젝트: yingkaisha/pyngl
lbres.lbTitleOffsetF       = 0.00

#---Create the labelbar
labels  = ["0","1","2","3"]
lbid = Ngl.labelbar_ndc (wks,len(labels),labels,0.0,0.,lbres)  

#
# Create some annotation resources indicating how we want to
# attach the labelbar to the plot. The default is the center
# of the plot. Below amOrthogonalPosF is set to move the
# labelbar down and outside the plot.
#                                                                 
amres                  = Ngl.Resources()
amres.amOrthogonalPosF =  0.7
annoid = Ngl.add_annotation(plot,lbid,amres)

txres = Ngl.Resources()
txres.txFontHeightF = 0.01
txres.txJust        = "TopRight"
txres.txPerimOn     = True
txid  = Ngl.add_text(wks,plot,flnm,res.mpMaxLonF,res.mpMaxLatF,txres)

#---This will resize plot so it and the labelbar fit in the frame.
Ngl.maximize_plot(wks, plot)

#---Drawing the original map also draws the attached labelbar.
Ngl.draw(plot)
Ngl.frame(wks)

Ngl.end()
예제 #8
0
  if arr[i-1] <= 0:
    lineres.gsLineColor = "blue"
  else:
    lineres.gsLineColor = "red"

  bars.append(Ngl.add_polyline(wks,plot,[iw1,iw1,iw2,iw2,iw1], \
                                        [0,arr[i-1],arr[i-1],0,0],lineres))

#
# Label boxes with text strings.
#

txres    = Ngl.Resources()
tstrings = []
txres.txFontHeightF = 0.009      
tstrings.append(Ngl.add_text(wks,plot,"CO~B~2~N~",1,-3.,txres))
tstrings.append(Ngl.add_text(wks,plot,"CH~B~4~N~ + N~B~2~N~O",2,-.97,txres))
tstrings.append(Ngl.add_text(wks,plot,"Mineral Dust",3,-2.4,txres))
tstrings.append(Ngl.add_text(wks,plot,"Continental ice",4,-4.35,txres))
tstrings.append(Ngl.add_text(wks,plot,"+ sea level",4,-4.6,txres))
tstrings.append(Ngl.add_text(wks,plot,"Vegetation",5,-1.77,txres))
tstrings.append(Ngl.add_text(wks,plot,"Orbital",6,0.45,txres))

#
# Draw two vertical strings on left side of plot.
#
txres.txFontHeightF = 0.009
txres.txAngleF      = 90.
Ngl.text_ndc(wks,"cooling",0.11,0.835,txres)
Ngl.text_ndc(wks,"warming",0.11,0.95,txres) 
예제 #9
0
dirc = Ngl.pynglpath("data")
f    = Nio.open_file(os.path.join(dirc,"cdf","uv300.nc"))
u    = f.variables["U"][0,:,8]
lat  = f.variables["lat"][:]

#---Start the graphics section
wks_type = "png"
wks = Ngl.open_wks (wks_type,"newcolor2")     # Open "newcolor2.png" for graphics

#---Set some resources.
res          = Ngl.Resources()
res.nglDraw  = False
res.nglFrame = False

plot  = Ngl.xy (wks,lat,u,res)              # Create plot

txres                = Ngl.Resources()         # text mods desired
txres.txFont         = 30
txres.txFontHeightF  = 0.04                    # font smaller. default big
txres.txFontOpacityF = 0.10                    # highly transparent
txres.txAngleF       = 45.

txid = Ngl.add_text(wks,plot,"Preliminary Data",10,15,txres) 

Ngl.draw(plot)        # Drawing plot will draw attached text
Ngl.frame(wks)        # Advance frame


Ngl.end()

예제 #10
0
def add_labels_lcm(wks,map,dlat,dlon):
  PI         = 3.14159
  RAD_TO_DEG = 180./PI

#-- determine whether we are in northern or southern hemisphere
  if (float(minlat) >= 0. and float(maxlat) > 0.):
     HEMISPHERE = "NH"
  else:
     HEMISPHERE = "SH"

#-- pick some "nice" values for the latitude labels.
  lat_values = np.arange(int(minlat),int(maxlat),10)
  lat_values = lat_values.astype(float)
  nlat       = len(lat_values)

#-- We need to get the slope of the left and right min/max longitude lines.
#-- Use NDC coordinates to do this.
  lat1_ndc = 0.
  lon1_ndc = 0.
  lat2_ndc = 0.
  lon2_ndc = 0.
  lon1_ndc,lat1_ndc = Ngl.datatondc(map,minlon,lat_values[0])
  lon2_ndc,lat2_ndc = Ngl.datatondc(map,minlon,lat_values[nlat-1])
  slope_lft         = (lat2_ndc-lat1_ndc)/(lon2_ndc-lon1_ndc)

  lon1_ndc,lat1_ndc = Ngl.datatondc(map,maxlon,lat_values[0])
  lon2_ndc,lat2_ndc = Ngl.datatondc(map,maxlon,lat_values[nlat-1])
  slope_rgt         = (lat2_ndc-lat1_ndc)/(lon2_ndc-lon1_ndc)
  
#-- set some text resources
  txres               = Ngl.Resources()
  txres.txFontHeightF = 0.01
  txres.txPosXF       = 0.1

#-- Loop through lat values, and attach labels to the left and right edges of
#-- the masked LC plot. The labels will be rotated to fit the line better.
  dum_lft       = []                            #-- assign arrays
  dum_rgt       = []                            #-- assign arrays
  lat_label_lft = []                            #-- assign arrays
  lat_label_rgt = []                            #-- assign arrays

  for n in range(0,nlat):
#-- left label
    if(HEMISPHERE == "NH"):
       rotate_val = -90.
       direction  = "N"
    else:
       rotate_val =  90.
       direction  = "S"

#-- add extra white space to labels
    lat_label_lft.append("{}~S~o~N~{}              ".format(str(np.abs(lat_values[n])),direction))
    lat_label_rgt.append("              {}~S~o~N~{}".format(str(np.abs(lat_values[n])),direction))
        
    txres.txAngleF = RAD_TO_DEG * np.arctan(slope_lft) + rotate_val
                             
    dum_lft.append(Ngl.add_text(wks,map,lat_label_lft[n],minlon,lat_values[n],txres))

#-- right label
    if(HEMISPHERE == "NH"):
       rotate_val =  90
    else:
       rotate_val = -90

    txres.txAngleF = RAD_TO_DEG * np.arctan(slope_rgt) + rotate_val

    dum_rgt.append(Ngl.add_text(wks,map,lat_label_rgt[n],maxlon,lat_values[n],txres))

#----------------------------------------------------------------------
# Now do longitude labels. These are harder because we're not adding
# them to a straight line.
# Loop through lon values, and attach labels to the bottom edge for
# northern hemisphere, or top edge for southern hemisphere.
#----------------------------------------------------------------------
  del(txres.txPosXF)
  txres.txPosYF = -5.0

#-- pick some "nice" values for the longitude labels
  lon_values = np.arange(int(minlon+10),int(maxlon-10),10).astype(float)
  lon_values = np.where(lon_values > 180, 360-lon_values, lon_values)
  nlon       = lon_values.size

  dum_bot    = []                            #-- assign arrays
  lon_labels = []                            #-- assign arrays

  if(HEMISPHERE == "NH"):
     lat_val    = minlat
  else:
     lat_val    = maxlat

  ctrl = "~C~"

  for n in range(0,nlon):
    if(lon_values[n] < 0):
       if(HEMISPHERE == "NH"):
          lon_labels.append("{}~S~o~N~W{}".format(str(np.abs(lon_values[n])),ctrl))
       else:
          lon_labels.append("{}{}~S~o~N~W".format(ctrl,str(np.abs(lon_values[n]))))
    elif(lon_values[n] > 0):
       if(HEMISPHERE == "NH"):
          lon_labels.append("{}~S~o~N~E{}".format(str(lon_values[n]),ctrl))
       else:
          lon_labels.append("{}{}~S~o~N~E".format(ctrl,str(lon_values[n])))
    else:
       if(HEMISPHERE == "NH"):
          lon_labels.append("{}0~S~o~N~{}".format(ctrl,ctrl))
       else:
          lon_labels.append("{}0~S~o~N~{}".format(ctrl,ctrl))

#-- For each longitude label, we need to figure out how much to rotate
#-- it, so get the approximate slope at that point.
    if(HEMISPHERE == "NH"):             #-- add labels to bottom of LC plot
       lon1_ndc,lat1_ndc = Ngl.datatondc(map, lon_values[n]-0.5, minlat)
       lon2_ndc,lat2_ndc = Ngl.datatondc(map, lon_values[n]+0.5, minlat)
       txres.txJust = "TopCenter"
    else:                               #-- add labels to top of LC plot
       lon1_ndc,lat1_ndc = Ngl.datatondc(map, lon_values[n]+0.5, maxlat)
       lon2_ndc,lat2_ndc = Ngl.datatondc(map, lon_values[n]-0.5, maxlat)
       txres.txJust = "BottomCenter"

    slope_bot = (lat1_ndc-lat2_ndc)/(lon1_ndc-lon2_ndc)
    txres.txAngleF  =  RAD_TO_DEG * np.arctan(slope_bot)
    
#-- attach to map
    dum_bot.append(Ngl.add_text(wks, map, str(lon_labels[n]), \
                                lon_values[n], lat_val, txres))
  return
예제 #11
0
xdots2 = x[42:48:5]
ydots2 = y[42:48:5]
prim13 = Ngl.add_polyline(wks, xy2, x[42:48], y[42:48], gsres)
prim14 = Ngl.add_polymarker(wks, xy2, xdots2, ydots2, gsres)

#
# Now add some text strings.
#
txres = Ngl.Resources()
txres.txFont = "helvetica-bold"
txres.txFontColor = "coral4"
txres.txFontHeightF = 0.037
txres.txJust = "BottomCenter"

text1 = Ngl.add_text(wks, xy1, "this is a text string", 32., 0.5, txres)

#
# Slanted strings
#
txres.txJust = "BottomRight"
txres.txAngleF = -45.
text2b = Ngl.add_text(wks, xy2, "some slanted", 32., .5, txres)
txres.txJust = "BottomLeft"
txres.txAngleF = 45.
text2b = Ngl.add_text(wks, xy2, "text strings", 32., .5, txres)

#
# Filled text box.
#
txres.txAngleF = 0.
예제 #12
0
def simple_contour(lons, lats, vals, cfg):
    """
    Generate a simple contour plot, okay 
    """
    tmpfp = tempfile.mktemp()
    rlist = Ngl.Resources()
    if cfg.has_key("wkColorMap"):
        rlist.wkColorMap = cfg['wkColorMap']
    #rlist.wkOrientation = "landscape"

    # Create Workstation
    wks = Ngl.open_wks( "ps",tmpfp,rlist)
 
    # Create Analysis
    if cfg.has_key("_conus"):
        analysis, res = grid_conus(lons, lats, vals)
    elif cfg.get("_northeast", False):
        analysis, res = grid_northeast(lons, lats, vals)
    elif cfg.get("_midwest", False):
        analysis, res = grid_midwest(lons, lats, vals)
    else:
        analysis, res = grid_iowa(lons, lats, vals)
    analysis = numpy.transpose(analysis)

    for key in cfg.keys():
        if key == 'wkColorMap' or key[0] == "_":
            continue
        setattr(res, key, cfg[key])
    if cfg.has_key("_MaskZero"):
        mask = numpy.where( analysis <= 0.02, True, False)
        analysis = numpy.ma.array(analysis, mask=mask)

    # Generate Contour
    if numpy.min(analysis) == numpy.max(analysis):
        if cfg.has_key("_conus"):
            res = conus()
        elif cfg.has_key("_midwest"):
            res = midwest()
        else:
            res = iowa()
        contour = Ngl.map(wks, res)
    else:
        contour = Ngl.contour_map(wks,analysis,res)

    if cfg.has_key("_showvalues") and cfg['_showvalues']:
        txres              = Ngl.Resources()
        txres.txFontHeightF = 0.012
        for i in range(len(lons)):
            if cfg.has_key("_valuemask") and cfg['_valuemask'][i] is False:
                continue
            Ngl.add_text(wks, contour, cfg["_format"] % vals[i], 
                     lons[i], lats[i],txres)

    Ngl.draw( contour )

    watermark(wks)
    manual_title(wks, cfg)
    vpbox(wks)
    Ngl.frame(wks)
    del wks
    return tmpfp
예제 #13
0
def simple_grid_fill(xaxis, yaxis, grid, cfg):
    """
    Generate a simple plot, but we already have the data!
    """
    tmpfp = tempfile.mktemp()
    rlist = Ngl.Resources()
    if cfg.has_key("wkColorMap"):
        rlist.wkColorMap = cfg['wkColorMap']
    #rlist.wkOrientation = "landscape"

    # Create Workstation
    wks = Ngl.open_wks( "ps",tmpfp,rlist)
    if cfg.has_key("_conus"):
        res = conus()
    elif cfg.get("_midwest", False):
        res = midwest()
    elif cfg.get("_louisiana", False):
        res = louisiana2()
    else:
        res = iowa2()

    if cfg.has_key("_MaskZero"):
        mask = numpy.where( grid <= 0.01, True, False)
        grid = numpy.ma.array(grid, mask=mask)
 
    for key in cfg.keys():
        if key == 'wkColorMap' or key[0] == "_":
            continue
        setattr(res, key, cfg[key])
    res.sfXArray = xaxis
    res.sfYArray = yaxis
    # Generate Contour
    contour = Ngl.contour_map(wks,grid,res)

#    if cfg.has_key("_showvalues") and cfg['_showvalues']:
#        txres              = Ngl.Resources()
#        txres.txFontHeightF = 0.012
#        for i in range(len(xaxis)):
#            if cfg.has_key("_valuemask") and cfg['_valuemask'][i] is False:
#                continue
#            Ngl.add_text(wks, contour, cfg["_format"] % vals[i], 
#                     lons[i], lats[i],txres)

    if cfg.has_key('_drawx'):
        for lo, la in zip(cfg['_drawx'], cfg['_drawy']):
            #print 'Adding Polygon!'
            plres  = Ngl.Resources() 
            plres.gsEdgesOn   = True      
            plres.gsEdgeColor = "black"
            plres.gsFillColor = -1
            Ngl.add_polygon(wks, contour, lo, la, plres)




    if cfg.get("_showvalues", False):
        txres              = Ngl.Resources()
        txres.txFontHeightF = 0.012
        (rows, cols) = numpy.shape(xaxis)
        for row in range(rows):
            for col in range(cols):
                if xaxis[row,col] > res.mpMinLonF and xaxis[row,col] < res.mpMaxLonF and yaxis[row,col] > res.mpMinLatF and yaxis[row,col] < res.mpMaxLatF:
                    Ngl.add_text(wks, contour, cfg["_format"] % grid[row, col], 
                                 xaxis[row, col], yaxis[row, col], txres)
    Ngl.draw(contour)

    if cfg.get('_watermark', True):
        watermark(wks)
    manual_title(wks, cfg)
    Ngl.frame(wks)
    del wks

    return tmpfp
예제 #14
0
def simple_valplot(lons, lats, vals, cfg):
    """
    Generate a simple plot of values on a map!
    """
    tmpfp = tempfile.mktemp()

    rlist = Ngl.Resources()
    if cfg.has_key("wkColorMap"):
        rlist.wkColorMap = cfg['wkColorMap']
    #rlist.wkOrientation = "landscape"

    # Create Workstation
    wks = Ngl.open_wks( "ps",tmpfp,rlist)
    if cfg.has_key("_conus"):
        res = conus()
    elif cfg.get("_midwest", False):
        res = midwest()
    else:
        res = iowa()
    if cfg.has_key("_spatialDataLimiter"):
        xmin, ymin, xmax, ymax = [ min(lons), min(lats), 
                                        max(lons), max(lats) ]
        res.mpMinLonF    = xmin - 0.25
        res.mpMaxLonF    = xmax + 0.25
        res.mpMinLatF    = ymin - 0.25
        res.mpMaxLatF    = ymax + 0.25
        res.mpCenterLonF = (xmax + xmin)/2.0  # Central Longitude
        res.mpCenterLatF = (ymax + ymin)/2.0  # Central Latitude
    res.mpOutlineDrawOrder = "PreDraw"
    res.mpUSStateLineColor = 10
    res.mpNationalLineColor = 10

    for key in cfg.keys():
        if key == 'wkColorMap' or key[0] == "_":
            continue
        setattr(res, key, cfg[key])

    plot = Ngl.map(wks, res)
    if cfg.has_key("_stationplot"):
        Ngl.wmsetp("col", 1)
        Ngl.wmsetp("ezf",1)
        if cfg.has_key("_removeskyc"):
            Ngl.wmsetp("WBC", 0.001) # Get rid of sky coverage
            Ngl.wmsetp("WBF", 0) # Put barb at center, no sky coverage
            Ngl.wmsetp("WBR", 0.001) # Size of calm circle
        #Ngl.wmsetp("WBL", 0.18) # Size of labels
        #Ngl.wmsetp("WBS", 0.029) # Size of wind barb shaft
        Ngl.wmstnm(wks, lats, lons, vals)
    else:
        txres              = Ngl.Resources()
        txres.txFontHeightF = 0.014
        txres.txJust        = "BottomCenter"
        for i in range(len(lons)):
            Ngl.add_text(wks, plot, cfg.get("_format",'%s') % vals[i], 
                      lons[i], lats[i],txres)
    if cfg.has_key("_labels"):
        txres               = Ngl.Resources()
        txres.txFontHeightF = 0.008
        txres.txJust        = "TopCenter"
        txres.txFontColor   = 14
        for i in range(len(lons)):
            Ngl.add_text(wks, plot, cfg["_labels"][i], 
                     lons[i], lats[i],txres)

    watermark(wks)
    manual_title(wks, cfg)
    Ngl.draw(plot)
    vpbox(wks)
    Ngl.frame(wks)
    del wks

    return tmpfp

    vpbox(wks)
예제 #15
0
파일: hdf1.py 프로젝트: Python3pkg/pyngl
lbres.lbTitleOffsetF       = 0.00

#---Create the labelbar
labels  = ["0","1","2","3"]
lbid = Ngl.labelbar_ndc (wks,len(labels),labels,0.0,0.,lbres)  

#
# Create some annotation resources indicating how we want to
# attach the labelbar to the plot. The default is the center
# of the plot. Below amOrthogonalPosF is set to move the
# labelbar down and outside the plot.
#                                                                 
amres                  = Ngl.Resources()
amres.amOrthogonalPosF =  0.7
annoid = Ngl.add_annotation(plot,lbid,amres)

txres = Ngl.Resources()
txres.txFontHeightF = 0.01
txres.txJust        = "TopRight"
txres.txPerimOn     = True
txid  = Ngl.add_text(wks,plot,flnm,res.mpMaxLonF,res.mpMaxLatF,txres)

#---This will resize plot so it and the labelbar fit in the frame.
Ngl.maximize_plot(wks, plot)

#---Drawing the original map also draws the attached labelbar.
Ngl.draw(plot)
Ngl.frame(wks)

Ngl.end()
예제 #16
0
    if arr[i - 1] <= 0:
        lineres.gsLineColor = "blue"
    else:
        lineres.gsLineColor = "red"

    bars.append(Ngl.add_polyline(wks,plot,[iw1,iw1,iw2,iw2,iw1], \
                                          [0,arr[i-1],arr[i-1],0,0],lineres))

#
# Label boxes with text strings.
#

txres = Ngl.Resources()
tstrings = []
txres.txFontHeightF = 0.009
tstrings.append(Ngl.add_text(wks, plot, "CO~B~2~N~", 1, -3., txres))
tstrings.append(
    Ngl.add_text(wks, plot, "CH~B~4~N~ + N~B~2~N~O", 2, -.97, txres))
tstrings.append(Ngl.add_text(wks, plot, "Mineral Dust", 3, -2.4, txres))
tstrings.append(Ngl.add_text(wks, plot, "Continental ice", 4, -4.35, txres))
tstrings.append(Ngl.add_text(wks, plot, "+ sea level", 4, -4.6, txres))
tstrings.append(Ngl.add_text(wks, plot, "Vegetation", 5, -1.77, txres))
tstrings.append(Ngl.add_text(wks, plot, "Orbital", 6, 0.45, txres))

#
# Draw two vertical strings on left side of plot.
#
txres.txFontHeightF = 0.009
txres.txAngleF = 90.
Ngl.text_ndc(wks, "cooling", 0.11, 0.835, txres)
Ngl.text_ndc(wks, "warming", 0.11, 0.95, txres)