コード例 #1
0
    def contour_map(self):
        params_dict = self.params_dict
        color_labels = self.color_labels
        color_levels = self.color_levels
        cn_fill_colors = np.arange(0,color_levels,1)

        nboxes = np.shape(cn_fill_colors)[0]

        # labels = [""] * nboxes
        #3.图例解释数据
        # if (self.output_img_name.contains("RH") or self.output_img_name.contains("TK")):
        #     labels[0] = "NoData"
        #     labels[1] = "<" + str(cn_levels[1])
        #     labels[nboxes - 1] = ">" + str(cn_levels[nboxes - 2])
        #     for i in range(2, nboxes - 1):
        #         labels[i] = str(cn_levels[i - 1]) + "~" + str(cn_levels[i])
        # else:
        #     labels[0] = "<" + str(cn_levels[0])
        #     labels[nboxes - 1] = ">" + str(cn_levels[nboxes - 2])
        #     for i in range(1, nboxes - 1):
        #         labels[i] = str(cn_levels[i - 1]) + "~" + str(cn_levels[i])

        #4.其他配置
        params_dict['vpHeightF'] = 0.022 * 0.868 * (nboxes + 3 - (nboxes - 5) / 2.8)
        params_dict['lbFillColors'] = cn_fill_colors
        if (self.output_img_name.contains("TK")):
            params_dict["lbLabelFontHeightF"] = 0.009
        else:
            params_dict["lbLabelFontHeightF"] = 0.009677
        lbres = create_or_update_resource(params_dict=params_dict)
        lbid = Ngl.labelbar_ndc(self.workstation, nboxes, color_labels, 0, 0, lbres)

        #5.色标位置配置
        lblres = create_or_update_resource(params_dict=self.location_params_dict)
        Ngl.add_annotation(self.plot, lbid, lblres)
コード例 #2
0
ファイル: ngl_contrib.py プロジェクト: martinclaus/py-clim
def lb_create_labelbar(wks, vpXY, vpWH, nboxes=11, levels=(-1., 1.),
                       fmt_str="{}", rlist=None):
    '''Creates a label bar.

    lb = lb_create_labelbar(wks, vpXY, vpWH, nboxes=11, levels=(-1., 1.),
                       frm_str="{}", rlist=None)

    wks : workstation Id as returned by open_wks()

    vpXY : tupel of upper left coordinates of the label bar's view port in NDC

    vpWH : tupel containing width and height of the label bar's view port
    in NDC

    nboxes : number of boxes

    levels : tupel containing the data extrems

    fmt_str : format string used to format the numbers

    rlist : Resource object containing additional resources that are accepted
    by labelbar_ndc()
    '''
    # add label bar for depth
    levels = np.linspace(*levels, num=nboxes)
    labels = [fmt_str.format(val) for val in levels]
    labres = {"lbAutoManage": False,
              "vpWidthF": vpWH[0],
              "vpHeightF": vpWH[1],
              "lbMonoFillPattern": 21,
              "lbOrientation": "vertical",
              "lbFillColors": map_data_to_color(wks, levels),
              "lbLabelStride": 10}
    if rlist:
        labres.update(rlist.__dict__)
    lb = ngl.labelbar_ndc(wks, nboxes, labels, *vpXY,
                          rlistc=_dict2Resource(labres))
    return lb
コード例 #3
0
  lines = []
  for seg in range(startSegment, startSegment+numSegments):
    startPT = segments[seg, segs_xyzIndex]
    endPT = startPT + segments[seg, segs_numPnts] - 1
    lines.append(Ngl.add_polygon(wks, plot, lon[startPT:endPT],  \
                                 lat[startPT:endPT], plres))
    segNum = segNum + 1

Ngl.draw(plot)

# Make a labelbar...
labels = [ "1", "2", "3", "4" ]

lres                    = Ngl.Resources()
lres.vpWidthF           = 0.50             # location
lres.vpHeightF          = 0.05             # " " 
lres.lbPerimOn          = False            # Turn off perimeter.
lres.lbOrientation      = "Horizontal"     # Default is vertical.
lres.lbLabelAlignment   = "BoxCenters"     # Default is "BoxCenters".
lres.lbFillColors       = colors
lres.lbMonoFillPattern  = True             # Fill them all solid.
lres.lbLabelFontHeightF = 0.012            # label font height
lres.lbTitleString      = "percent"        # title
lres.lbTitlePosition    = "Bottom"         # location of title
lres.lbTitleFontHeightF = 0.01             # title font height
Ngl.labelbar_ndc (wks,4,labels,0.23,0.15,lres)  
  
Ngl.frame(wks)  # Advance the frame.

Ngl.end()
コード例 #4
0
#-- draw polygons
polyg  = Ngl.add_polygon(wks1,map,x1d,y1d,pgres)          #-- add polygons to map

#-- labelbar resources
lbres                             =  Ngl.Resources()
lbres.vpWidthF                    =  0.85                 #-- labelbar width
lbres.vpHeightF                   =  0.15                 #-- labelbar height
lbres.lbOrientation               = "Horizontal"          #-- labelbar orientation
lbres.lbFillPattern               = "SolidFill"           #-- labelbar box fill style
lbres.lbMonoFillPattern           =  21                   #-- labelbar box fill pattern
lbres.lbMonoFillColor             =  False                #-- use multiple colors
lbres.lbFillColors                =  colors               #-- set color array
lbres.lbLabelFontHeightF          =  0.014                #-- labelbar label font size
lbres.lbLabelAlignment            = "InteriorEdges"       #-- draw labels between boxes

#-- add labelbar to workstation
lb = Ngl.labelbar_ndc(wks1,nlevels,labels,0.1,0.2,lbres)

#-- maximize and draw the plot, and advance the frame
Ngl.maximize_plot(wks1, map)
Ngl.draw(map)
Ngl.frame(wks1)

#-- get wallclock time
t2 = time.time()
print "Wallclock time:  %0.3f seconds" % (t2-t1)
print ""

Ngl.end()
コード例 #5
0
polyg = Ngl.add_polygon(wks1, map, x1d, y1d, pgres)

#-- add a labelbar
lbres = Ngl.Resources()
lbres.vpWidthF = 0.85
lbres.vpHeightF = 0.15
lbres.lbOrientation = 'Horizontal'
lbres.lbFillPattern = 'SolidFill'
lbres.lbMonoFillPattern = 21  #-- must be 21 for color solid fill
lbres.lbMonoFillColor = False  #-- use multiple colors
lbres.lbFillColors = colors  #-- indices from loaded colormap
lbres.lbBoxCount = len(colormap[colors, :])
lbres.lbLabelFontHeightF = 0.014
lbres.lbLabelAlignment = 'InteriorEdges'
lbres.lbLabelStrings = labels

lb = Ngl.labelbar_ndc(wks1, nlevs + 1, labels, 0.1, 0.24, lbres)

#-- maximize and draw the plot and advance the frame
Ngl.maximize_plot(wks1, map)
Ngl.draw(map)
Ngl.frame(wks1)

#-- get wallclock time
t2 = time.time()
print('')
print('Wallclock time:  %0.3f seconds' % (t2 - t1))
print('')

Ngl.end()
コード例 #6
0
ファイル: labelbar.py プロジェクト: yingkaisha/pyngl
#
#  Import Ngl support functions.
#
import Ngl

wkres = Ngl.Resources()
wkres.wkColorMap = "default"
wks_type = "ps"
wks = Ngl.open_wks(wks_type, "labelbar", wkres)

labels = ["One", "Two", "Three", "Four", "Five", "Six"]

#
# Generate a labelbar with the default settings.
#
lb = Ngl.labelbar_ndc(wks, 5, labels, 0.3, 0.9)
Ngl.frame(wks)

#
# Change the font and alignment of the labels.
#
rlist = Ngl.Resources()
rlist.lbLabelFont = "Times-Bold"
rlist.lbLabelAlignment = "InteriorEdges"

lb = Ngl.labelbar_ndc(wks, 5, labels, 0.3, 0.9, rlist)
Ngl.frame(wks)

#
# Change the size, orientation, the fill to solid fill.
#
コード例 #7
0
ファイル: color6.py プロジェクト: zhishang80/pyngl
def draw_colormap(wks, cmap):

    #---Read as RGBA array
    cmapr = Ngl.read_colormap_file(cmap)

    #---Set some options
    orientation = "horizontal"  #  "horizontal" or "vertical"
    lbres = Ngl.Resources()

    if (orientation == "vertical"):
        width = 0.2
        height = 1.0  # full height of viewport
        xpos = 0.5 - width / 2.  # centered
        ypos = 1.0  # flush w/top of viewport
    else:
        height = 0.2
        width = 1.0  # full width of viewport
        xpos = 0.0  # flush right
        ypos = 0.5 + height / 2.  # centered

    lbres.vpWidthF = width
    lbres.vpHeightF = height
    lbres.lbOrientation = orientation
    lbres.lbLabelsOn = False
    lbres.lbBoxLinesOn = False

    #---Make sure labelbar fills the viewport region we specified
    lbres.lbBoxMinorExtentF = 1.0
    lbres.lbTopMarginF = 0.0
    lbres.lbBottomMarginF = 0.0
    lbres.lbRightMarginF = 0.0
    lbres.lbLeftMarginF = 0.0

    #---Necessary so we get all solid fill
    lbres.lbMonoFillPattern = True
    lbres.lbFillColors = cmapr

    cmaplen = cmapr.shape[0]
    labels = ["" for x in range(cmaplen)]

    lbid = Ngl.labelbar_ndc(wks, cmaplen, labels, xpos, ypos, lbres)
    Ngl.draw(lbid)

    #---Draw a box around the labelbar
    xbox = [xpos, xpos + width, xpos + width, xpos, xpos]
    ybox = [ypos, ypos, ypos - height, ypos - height, ypos]

    lnres = Ngl.Resources()
    lnres.gsLineThicknessF = 1.5
    Ngl.polyline_ndc(wks, xbox, ybox, lnres)

    lnres = Ngl.Resources()
    lnres.gsLineThicknessF = 1.5
    Ngl.polyline_ndc(wks, xbox, ybox, lnres)

    #---Add name of the color map
    txres = Ngl.Resources()
    txres.txFontHeightF = 0.02
    if (orientation == "vertical"):
        txres.txJust = "TopRight"
        Ngl.text_ndc(wks, cmap, xpos, 1.0, txres)
    else:
        txres.txJust = "BottomCenter"
        Ngl.text_ndc(wks, cmap, 0.5, ypos, txres)

    Ngl.frame(wks)  # Advance the frame
コード例 #8
0
ファイル: hdf1.py プロジェクト: yingkaisha/pyngl
lbres.lbOrientation        = "Horizontal"
lbres.lbLabelPosition      = "Center"         # label position
lbres.lbFillColors         = colors[2:]
lbres.lbMonoFillPattern    = True             # solid color fill
lbres.lbLabelFontHeightF   = 0.02

lbres.lbTitleOn            = True
lbres.lbTitleString        = "0=cldy, 1=uncertain, 2=prob clr, 3=clr"
lbres.lbTitlePosition      = "Bottom"
lbres.lbTitleFontHeightF   = 0.02
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
コード例 #9
0
ファイル: clmdiv2.py プロジェクト: yingkaisha/pyngl
for j in range(1,nboxes):
  labels[j] = " "

lbres                    = Ngl.Resources()
lbres.vpWidthF           = 0.70
lbres.vpHeightF          = 0.10
lbres.lbPerimOn          = False            # Turn off perimeter.
lbres.lbOrientation      = "Horizontal"     # Default is vertical.
lbres.lbLabelAlignment   = "ExternalEdges"  
lbres.lbFillColors       = colors
lbres.lbMonoFillPattern  = True             # Fill them all solid.
lbres.lbLabelFontHeightF = 0.013            # label font height
lbres.nglDraw            = False

# The labelbar will be created, but not drawn at this point.
lbid = Ngl.labelbar_ndc(wks,nboxes,labels,0.5,0.2,lbres)

#
# Now create some annotation resources indicating how we want to
# attach the labelbar to the plot. Here, we are using the top center
# of the labelbar as the point which we are going to position
# it, and then we use amOrthogonalPosF to move it down.
#
# amParallelPosF/amOrthogonalPosF
#    0.0/ 0.0  -  annotation in dead center of plot
#    0.5/ 0.5  -  annotation at bottom right of plot
#    0.5/-0.5  -  annotation at top right of plot
#   -0.5/-0.5  -  annotation at top left of plot
#   -0.5/ 0.5  -  annotation at bottom left of plot
#                                                                 
amres = Ngl.Resources()
コード例 #10
0
#  Import Ngl support functions.
#
from __future__ import print_function
import Ngl

wkres = Ngl.Resources()
wkres.wkColorMap = "default"
wks_type = "png"
wks = Ngl.open_wks(wks_type, "labelbar", wkres)

labels = ["One", "Two", "Three", "Four", "Five", "Six"]

#
# Generate a labelbar with the default settings.
#
lb = Ngl.labelbar_ndc(wks, 5, labels, 0.3, 0.9)
Ngl.frame(wks)

#
# Change the font and alignment of the labels.
#
rlist = Ngl.Resources()
rlist.lbLabelFont = "Times-Bold"
rlist.lbLabelAlignment = "InteriorEdges"

lb = Ngl.labelbar_ndc(wks, 5, labels, 0.3, 0.9, rlist)
Ngl.frame(wks)

#
# Change the size, orientation, the fill to solid fill.
#
コード例 #11
0
ファイル: hdf1.py プロジェクト: Python3pkg/pyngl
lbres.lbOrientation        = "Horizontal"
lbres.lbLabelPosition      = "Center"         # label position
lbres.lbFillColors         = colors
lbres.lbMonoFillPattern    = True             # solid color fill
lbres.lbLabelFontHeightF   = 0.02

lbres.lbTitleOn            = True
lbres.lbTitleString        = "0=cldy, 1=uncertain, 2=prob clr, 3=clr"
lbres.lbTitlePosition      = "Bottom"
lbres.lbTitleFontHeightF   = 0.02
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
コード例 #12
0
lbx, lby = vpx, vpy - vph - 0.04

lbres = Ngl.Resources()
lbres.vpWidthF = vpw  #-- width of labelbar
lbres.vpHeightF = 0.08  #-- height of labelbar
lbres.lbOrientation = "horizontal"  #-- labelbar orientation
lbres.lbLabelFontHeightF = 0.012  #-- labelbar label font size
lbres.lbAutoManage = False  #-- we control label bar
lbres.lbFillColors = colors  #-- box fill colors
lbres.lbPerimOn = False  #-- turn off labelbar perimeter
lbres.lbMonoFillPattern = True  #-- turn on solid pattern
lbres.lbLabelAlignment = "BoxCenters"  #-- write labels below box edges

#-- create the labelbar
pid = Ngl.labelbar_ndc(wks, nlevels, labels, lbx, lby, lbres)

#-----------------------------------------------------------------------------------
#-- add x-axis title and copyright string
#-----------------------------------------------------------------------------------
txres = Ngl.Resources()
txres.txJust = "CenterCenter"
txres.txFontHeightF = 0.014

Ngl.text_ndc(wks, "ESGF users", 0.5, 0.14, txres)

txres.txJust = "CenterRight"
txres.txFontHeightF = 0.010
Ngl.text_ndc(wks, "~F35~c ~F21~~N~DKRZ", vpx + vpw, 0.10, txres)

#-----------------------------------------------------------------------------------
polyg  = Ngl.add_polygon(wks1,map,x1d,y1d,pgres)

#-- add a labelbar
lbres                   =  Ngl.Resources()
lbres.vpWidthF          =  0.85
lbres.vpHeightF         =  0.15
lbres.lbOrientation     = 'Horizontal'
lbres.lbFillPattern     = 'SolidFill'
lbres.lbMonoFillPattern =  21                       #-- must be 21 for color solid fill
lbres.lbMonoFillColor   =  False                    #-- use multiple colors
lbres.lbFillColors      =  colors                   #-- indices from loaded colormap
lbres.lbBoxCount        =  len(colormap[colors,:])
lbres.lbLabelFontHeightF=  0.014
lbres.lbLabelAlignment  = 'InteriorEdges'
lbres.lbLabelStrings    =  labels

lb = Ngl.labelbar_ndc(wks1,nlevs+1,labels,0.1,0.24,lbres)

#-- maximize and draw the plot and advance the frame
Ngl.maximize_plot(wks1, map)
Ngl.draw(map)
Ngl.frame(wks1)

#-- get wallclock time
t2 = time.time()
print ''
print 'Wallclock time:  %0.3f seconds' % (t2-t1)
print ''

Ngl.end()
コード例 #14
0
ファイル: shapefile1.py プロジェクト: yingkaisha/pyngl
  lines = []
  for seg in range(startSegment, startSegment+numSegments):
    startPT = segments[seg, segs_xyzIndex]
    endPT = startPT + segments[seg, segs_numPnts] - 1
    lines.append(Ngl.add_polygon(wks, plot, lon[startPT:endPT],  \
                                 lat[startPT:endPT], plres))
    segNum = segNum + 1

Ngl.draw(plot)

# Make a labelbar...
labels = [ "1", "2", "3", "4" ]

lres                    = Ngl.Resources()
lres.vpWidthF           = 0.50             # location
lres.vpHeightF          = 0.05             # " " 
lres.lbPerimOn          = False            # Turn off perimeter.
lres.lbOrientation      = "Horizontal"     # Default is vertical.
lres.lbLabelAlignment   = "BoxCenters"     # Default is "BoxCenters".
lres.lbFillColors       = colors
lres.lbMonoFillPattern  = True             # Fill them all solid.
lres.lbLabelFontHeightF = 0.012            # label font height
lres.lbTitleString      = "percent"        # title
lres.lbTitlePosition    = "Bottom"         # location of title
lres.lbTitleFontHeightF = 0.01             # title font height
Ngl.labelbar_ndc (wks,4,labels,0.23,0.15,lres)  
  
Ngl.frame(wks)  # Advance the frame.

Ngl.end()
コード例 #15
0
for j in range(1, nboxes):
    labels[j] = " "

lbres = Ngl.Resources()
lbres.vpWidthF = 0.70
lbres.vpHeightF = 0.10
lbres.lbPerimOn = False  # Turn off perimeter.
lbres.lbOrientation = "Horizontal"  # Default is vertical.
lbres.lbLabelAlignment = "ExternalEdges"
lbres.lbFillColors = colors
lbres.lbMonoFillPattern = True  # Fill them all solid.
lbres.lbLabelFontHeightF = 0.013  # label font height
lbres.nglDraw = False

# The labelbar will be created, but not drawn at this point.
lbid = Ngl.labelbar_ndc(wks, nboxes, labels, 0.5, 0.2, lbres)

#
# Now create some annotation resources indicating how we want to
# attach the labelbar to the plot. Here, we are using the top center
# of the labelbar as the point which we are going to position
# it, and then we use amOrthogonalPosF to move it down.
#
# amParallelPosF/amOrthogonalPosF
#    0.0/ 0.0  -  annotation in dead center of plot
#    0.5/ 0.5  -  annotation at bottom right of plot
#    0.5/-0.5  -  annotation at top right of plot
#   -0.5/-0.5  -  annotation at top left of plot
#   -0.5/ 0.5  -  annotation at bottom left of plot
#
amres = Ngl.Resources()