def tricolour(wks, xll, yll, height): # # Colors # blue_index = Ngl.new_color(wks, 0.00, 0.15, 0.50) white_index = Ngl.new_color(wks, 1.00, 1.00, 1.00) red_index = Ngl.new_color(wks, 1.00, 0.10, 0.14) width = 1.5 * height xx = numpy.zeros(5, 'f') yy = numpy.zeros(5, 'f') # # Draw blue bar. # xx = [xll, xll + width / 3., xll + width / 3., xll, xll] yy = [yll, yll, yll + height, yll + height, yll] pres = Ngl.Resources() pres.gsFillColor = blue_index Ngl.polygon_ndc(wks, xx, yy, pres) # # Draw white bar. # xx = [xll+width/3., xll + 2.*width/3., xll + 2.*width/3., \ xll+width/3., xll+width/3.] pres.gsFillColor = white_index Ngl.polygon_ndc(wks, xx, yy, pres) # # Draw red bar. # xx = [xll+2.*width/3., xll + width, xll + width, \ xll+2.*width/3., xll+2.*width/3.] pres.gsFillColor = red_index Ngl.polygon_ndc(wks, xx, yy, pres) xx = [xll, xll + width, xll + width, xll, xll] # # Perimeter. # pres.gsLineColor = 1 Ngl.polyline_ndc(wks, xx, yy, pres)
x[4], y[4] = x[0] , y[0] # # Convert the integer color values obtained from the # named color chart (as entered above) to floating # point numbers in the range 0. to 1. # r, g, b = colors[i][0]/255., colors[i][1]/255., colors[i][2]/255. poly_res.gsFillColor = [r,g,b] # Ngl.new_color(wks, r, g, b) # # Draw a white outline if the color is black, otherwise draw a colored box. # if (labels[i] == "Black"): Ngl.polyline_ndc(wks, x, y, poly_res) else: Ngl.polygon_ndc(wks, x, y, poly_res) # # Label the boxes. # text_res.txFontHeightF = 0.017 Ngl.text_ndc(wks, labels[i], 0.5*(x[0]+x[1]), y[0] + 0.0125, text_res) rgb_label = "R=%4.2f G=%4.2f B=%4.2f" % (r, g, b) text_res.txFontHeightF = 0.015 Ngl.text_ndc(wks, rgb_label, 0.5*(x[0]+x[1]), y[3] - 0.0125, text_res) # # Plot top and bottom labels. # text_res.txFontHeightF = 0.025 Ngl.text_ndc(wks, "Sixteen Sample Colors", 0.5, 0.96, text_res) text_res.txFontHeightF = 0.018
# Set up info for box. width = 0.07 # Box width height = 0.05 # Box height # Set coordinates for top left corner of the eight boxes. xpos = [0.20,0.40,0.60,0.80,0.20, 0.40, 0.60, 0.80] ypos = [0.13,0.13,0.13,0.13,0.055,0.055,0.055,0.055] # Text resources. txres = Ngl.Resources() txres.txFontHeightF = 0.015 # Decrease size of font txres.txJust = "CenterLeft" # Left justify nboxes = len(xpos) for i in xrange(nboxes): xp = xpos[i] yp = ypos[i] xbox = [xp,xp+width,xp+width,xp,xp] ybox = [yp,yp,yp-height,yp-height,yp] gsres.gsFillColor = colors[i+2] Ngl.polygon_ndc(wks,xbox,ybox,gsres) # Fill the box Ngl.polyline_ndc(wks,xbox,ybox) # Outline the box Ngl.text_ndc(wks,labels[i],xp+width+0.005,yp-height/2.,txres) Ngl.frame(wks) # Now advance the frame. Ngl.end()
# # Convert the integer color values obtained from the # named color chart (as entered above) to floating # point numbers in the range 0. to 1. (as required # by "Ngl.new_color"). # r, g, b = colors[i][0]/255., colors[i][1]/255., colors[i][2]/255. poly_res.gsFillColor = Ngl.new_color(wks, r, g, b) # # Draw a white outline if the color is black, otherwise draw a colored box. # if (labels[i] == "Black"): Ngl.polyline_ndc(wks, x, y, poly_res) else: Ngl.polygon_ndc(wks, x, y, poly_res) # # Label the boxes. # text_res.txFontHeightF = 0.017 Ngl.text_ndc(wks, labels[i], 0.5*(x[0]+x[1]), y[0] + 0.0125, text_res) rgb_label = "R=%4.2f G=%4.2f B=%4.2f" % (r, g, b) text_res.txFontHeightF = 0.015 Ngl.text_ndc(wks, rgb_label, 0.5*(x[0]+x[1]), y[3] - 0.0125, text_res) # # Plot top and bottom labels. # text_res.txFontHeightF = 0.025 Ngl.text_ndc(wks, "Sixteen Sample Colors", 0.5, 0.96, text_res) text_res.txFontHeightF = 0.018
def draw_gons(xshift=0.0, yshift=0.0): gnres = Ngl.Resources() # Polygon resources # The filled diamond gnres.gsFillColor = 98 xdia = numpy.array([0.00, 0.10, 0.20, 0.10, 0.00]) + xshift ydia = numpy.array([0.10, 0.00, 0.10, 0.20, 0.10]) + yshift Ngl.polygon_ndc(wks, xdia, ydia, gnres) # The filled four squares gnres.gsFillColor = 8 xbox = numpy.array([0.00, 0.05, 0.05, 0.00, 0.00]) + xshift ybox = numpy.array([0.00, 0.00, 0.05, 0.05, 0.00]) + yshift Ngl.polygon_ndc(wks, xbox, ybox, gnres) Ngl.polygon_ndc(wks, xbox + 0.15, ybox, gnres) Ngl.polygon_ndc(wks, xbox, ybox + 0.15, gnres) Ngl.polygon_ndc(wks, xbox + 0.15, ybox + 0.15, gnres) Ngl.polyline_ndc(wks, xbox, ybox) Ngl.polyline_ndc(wks, xbox + 0.15, ybox) Ngl.polyline_ndc(wks, xbox, ybox + 0.15) Ngl.polyline_ndc(wks, xbox + 0.15, ybox + 0.15) # The shaded slanted boxes attaching the squares gnres.gsFillColor = 73 xbt1 = numpy.array([0.05, 0.10, 0.10, 0.05, 0.05]) + xshift ybt1 = numpy.array([0.00, 0.05, 0.10, 0.05, 0.00]) + yshift xbt2 = ybt1 ybt2 = xbt1 xbt3 = xbt1 + 0.05 ybt3 = ybt1 + 0.10 xbt4 = ybt3 ybt4 = xbt3 gnres.gsFillColor = 1 gnres.gsFillIndex = 17 Ngl.polygon_ndc(wks, xbt1, ybt1, gnres) Ngl.polygon_ndc(wks, xbt2, ybt2, gnres) Ngl.polygon_ndc(wks, xbt3, ybt3, gnres) Ngl.polygon_ndc(wks, xbt4, ybt4, gnres) Ngl.polyline_ndc(wks, xbt1, ybt1, gnres) Ngl.polyline_ndc(wks, xbt2, ybt2, gnres) Ngl.polyline_ndc(wks, xbt3, ybt3, gnres) Ngl.polyline_ndc(wks, xbt4, ybt4, gnres) xtb1 = numpy.array([0.10, 0.15, 0.15, 0.10, 0.10]) + xshift ytb1 = numpy.array([0.05, 0.00, 0.05, 0.10, 0.05]) + yshift xtb2 = ytb1 ytb2 = xtb1 xtb3 = xtb1 - 0.05 ytb3 = ytb1 + 0.10 xtb4 = ytb3 ytb4 = xtb3 Ngl.polygon_ndc(wks, xtb1, ytb1, gnres) Ngl.polygon_ndc(wks, xtb2, ytb2, gnres) Ngl.polygon_ndc(wks, xtb3, ytb3, gnres) Ngl.polygon_ndc(wks, xtb4, ytb4, gnres) Ngl.polyline_ndc(wks, xtb1, ytb1, gnres) Ngl.polyline_ndc(wks, xtb2, ytb2, gnres) Ngl.polyline_ndc(wks, xtb3, ytb3, gnres) Ngl.polyline_ndc(wks, xtb4, ytb4, gnres)
iItem = i + j * shape[0] if (iItem + 1) > rlist["lgItemCount"]: break _lg_add_legend_item(wks, rlist["lgItemOrder"][iItem], (itemsXY[0][j], itemsXY[1][i]), itemsWH, rlist) def _lg_add_legend_perim(wks, (x, y), (w, h), res): bres = {} bres["gsEdgesOn"] = res["lgPerimOn"] for key in _filter_keys(res, "lgPerimFill"): bres["gsFill" + key] = res["lgPerimFill" + key] for key in _filter_keys(res, "lgPerim", exceptions=("On"), falsepositive="Fill"): bres["gsEdge" + key] = res["lgPerim" + key] ngl.polygon_ndc(wks, *_xywh2corners((x, y), (w, h)), rlistc=_dict2Resource(bres)) def _lg_add_legend_title(wks, (iXY, iWH), res): if not res["lgTitleOn"]: return x, y = list(res["vpXY"]) w, h = list(res["vpWH"]) offset = {"Top": (0, -res["lgTitleOffsetF"] * res["vpWH"][1]), "Bottom": (0, res["lgTitleOffsetF"] * res["vpWH"][1]), "Left": (res["lgTitleOffsetF"] * res["vpWH"][0], 0), "Right": (-res["lgTitleOffsetF"] * res["vpWH"][0], 0)} if res["lgTitlePosition"] in ("Top", "Bottom"): w = res["lgTitleExtentF"] * (res["vpWH"][1] - res["margin"]["Top"] - res["margin"]["Bottom"]) if res["lgTitlePosition"] == "Top":
def draw_gons(xshift=0.0,yshift=0.0): gnres = Ngl.Resources() # Polygon resources # The filled diamond gnres.gsFillColor = "lightpink1" xdia = numpy.array([0.00,0.10,0.20,0.10,0.00]) + xshift ydia = numpy.array([0.10,0.00,0.10,0.20,0.10]) + yshift Ngl.polygon_ndc(wks,xdia,ydia,gnres) # The filled four squares gnres.gsFillColor = "lightslateblue" xbox = numpy.array([0.00,0.05,0.05,0.00,0.00]) + xshift ybox = numpy.array([0.00,0.00,0.05,0.05,0.00]) + yshift Ngl.polygon_ndc(wks,xbox, ybox, gnres) Ngl.polygon_ndc(wks,xbox+0.15,ybox, gnres) Ngl.polygon_ndc(wks,xbox, ybox+0.15,gnres) Ngl.polygon_ndc(wks,xbox+0.15,ybox+0.15,gnres) Ngl.polyline_ndc(wks,xbox, ybox) Ngl.polyline_ndc(wks,xbox+0.15,ybox) Ngl.polyline_ndc(wks,xbox, ybox+0.15) Ngl.polyline_ndc(wks,xbox+0.15,ybox+0.15) # The shaded slanted boxes attaching the squares gnres.gsFillColor = "cyan" xbt1 = numpy.array([0.05,0.10,0.10,0.05,0.05]) + xshift ybt1 = numpy.array([0.00,0.05,0.10,0.05,0.00]) + yshift xbt2 = ybt1 ybt2 = xbt1 xbt3 = xbt1 + .05 ybt3 = ybt1 + .10 xbt4 = ybt3 ybt4 = xbt3 gnres.gsFillColor = "black" gnres.gsFillIndex = 17 Ngl.polygon_ndc(wks,xbt1,ybt1,gnres) Ngl.polygon_ndc(wks,xbt2,ybt2,gnres) Ngl.polygon_ndc(wks,xbt3,ybt3,gnres) Ngl.polygon_ndc(wks,xbt4,ybt4,gnres) Ngl.polyline_ndc(wks,xbt1,ybt1,gnres) Ngl.polyline_ndc(wks,xbt2,ybt2,gnres) Ngl.polyline_ndc(wks,xbt3,ybt3,gnres) Ngl.polyline_ndc(wks,xbt4,ybt4,gnres) xtb1 = numpy.array([0.10,0.15,0.15,0.10,0.10]) + xshift ytb1 = numpy.array([0.05,0.00,0.05,0.10,0.05]) + yshift xtb2 = ytb1 ytb2 = xtb1 xtb3 = xtb1 - .05 ytb3 = ytb1 + .10 xtb4 = ytb3 ytb4 = xtb3 Ngl.polygon_ndc(wks,xtb1,ytb1,gnres) Ngl.polygon_ndc(wks,xtb2,ytb2,gnres) Ngl.polygon_ndc(wks,xtb3,ytb3,gnres) Ngl.polygon_ndc(wks,xtb4,ytb4,gnres) Ngl.polyline_ndc(wks,xtb1,ytb1,gnres) Ngl.polyline_ndc(wks,xtb2,ytb2,gnres) Ngl.polyline_ndc(wks,xtb3,ytb3,gnres) Ngl.polyline_ndc(wks,xtb4,ytb4,gnres)
txres.txFont = 22 for i in xrange(4,14,1): x0 = startx+(i-4)*delx x1 = x0+delx x2 = x1 x3 = x0 x4 = x0 x = [x0,x1,x2,x3,x4] y0 = starty y1 = y0 y2 = y1+dely y3 = y2 y4 = y0 y = [y0,y1,y2,y3,y4] gsres.gsFillColor = i # Change fill color. Ngl.polygon_ndc(wks,x,y,gsres) Ngl.polyline_ndc(wks,x,y,gsres) if (i == 4): Ngl.text_ndc(wks,"34.55",x0,y0-dely,txres) elif(i == 6): Ngl.text_ndc(wks,"34.61",x0,y0-dely,txres) elif(i == 8): Ngl.text_ndc(wks,"34.67",x0,y0-dely,txres) elif(i == 10): Ngl.text_ndc(wks,"34.73",x0,y0-dely,txres) elif(i == 12): Ngl.text_ndc(wks,"34.79",x0,y0-dely,txres) Ngl.text_ndc(wks,"34.85",startx+10*delx,y0-dely,txres) # # Draw the trajectories.
# Loop on the saturations. # sindex = 0 for saturation in saturations: r, g, b = Ngl.hsvrgb(hue, saturation, value) poly_res.gsFillColor = [r, g, b] # Ngl.new_color(wks,r,g,b) rlen = 0.25 * (3. * saturation + 1.) x[1] = math.cos(angle1) * rlen y[1] = math.sin(angle1) * rlen x[2] = math.cos(angle2) * rlen y[2] = math.sin(angle2) * rlen xc = 0.1 + (x + 1.2) / 3. # Conceptual user space is [-1.2, 1.2] in yc = 0.1 + (y + 1.2) / 3. # X and Y -- map to [0.1, 0.9] NDC space. Ngl.polygon_ndc(wks, xc, yc, poly_res) x[0] = x[1] x[3] = x[2] y[0] = y[1] y[3] = y[2] # # Label the saturation levels (the zero saturation # level at the center of the wheel is not labeled). # if (saturation != 0.): text_res.txFontHeightF = 0.022 text_res.txJust = "CenterCenter" slabel = "S = %4.2f" % (saturation) Ngl.text_ndc(wks, slabel, 0.5, slab_y[sindex], text_res) sindex = sindex + 1
# Set up info for box. width = 0.07 # Box width height = 0.05 # Box height # Set coordinates for top left corner of the eight boxes. xpos = [0.20, 0.40, 0.60, 0.80, 0.20, 0.40, 0.60, 0.80] ypos = [0.13, 0.13, 0.13, 0.13, 0.055, 0.055, 0.055, 0.055] # Text resources. txres = Ngl.Resources() txres.txFontHeightF = 0.015 # Decrease size of font txres.txJust = "CenterLeft" # Left justify nboxes = len(xpos) for i in xrange(nboxes): xp = xpos[i] yp = ypos[i] xbox = [xp, xp + width, xp + width, xp, xp] ybox = [yp, yp, yp - height, yp - height, yp] gsres.gsFillColor = colors[i + 2] Ngl.polygon_ndc(wks, xbox, ybox, gsres) # Fill the box Ngl.polyline_ndc(wks, xbox, ybox) # Outline the box Ngl.text_ndc(wks, labels[i], xp + width + 0.005, yp - height / 2., txres) Ngl.frame(wks) # Now advance the frame. Ngl.end()
# # Loop on the saturations. # sindex = 0 for saturation in saturations: r,g,b = Ngl.hsvrgb(hue,saturation,value) poly_res.gsFillColor = Ngl.new_color(wks,r,g,b) rlen = 0.25*(3.*saturation + 1.) x[1] = math.cos(angle1) * rlen y[1] = math.sin(angle1) * rlen x[2] = math.cos(angle2) * rlen y[2] = math.sin(angle2) * rlen xc = 0.1 + (x + 1.2)/3. # Conceptual user space is [-1.2, 1.2] in yc = 0.1 + (y + 1.2)/3. # X and Y -- map to [0.1, 0.9] NDC space. Ngl.polygon_ndc(wks,xc,yc,poly_res) x[0] = x[1] x[3] = x[2] y[0] = y[1] y[3] = y[2] # # Label the saturation levels (the zero saturation # level at the center of the wheel is not labeled). # if (saturation != 0.): text_res.txFontHeightF = 0.022 text_res.txJust = "CenterCenter" slabel = "S = %4.2f" % (saturation) Ngl.text_ndc(wks, slabel, 0.5, slab_y[sindex],text_res) sindex = sindex+1