demostracion.del.modulo8!

Ejemplos de scripts: Codigo en Python: code File:
 * 1)    multi_y.py
 * 2)  Synopsis:
 * 3)    Shows how to conflate two XY plots and how to add and remove annotations.
 * 4)  Categories:
 * 5)    Annotations
 * 6)    XY plots
 * 7)    Special effects
 * 8)  Author:
 * 9)    Mary Haley
 * 10)  Date of initial publication:
 * 11)    August, 2005
 * 12)  Description:
 * 13)    This example shows:
 * 14)       1.)  how to merge two XY plots into a single visualization
 * 15)       2.)  how to do the same thing as in 1.) by specifying
 * 16)            the second plot as an annotation to the first
 * 17)       3.)  how to remove an annotation
 * 18)  Effects illustrated:
 * 19)    o  Reading data from an ASCII file.
 * 20)    o  Controlling two separate plots so that they will have the
 * 21)       same size an position on the frame.
 * 22)    o  Setting several tickmark resources to turn some off and
 * 23)       label others with user-specified labels and so forth.
 * 24)    o  XY plots.
 * 25)    o  Adding and removing annotations.
 * 26)    o  Creating your own dash pattern.
 * 27)  Output:
 * 28)    Five visualizations are produced:
 * 29)      1.)  A simple XY plot.
 * 30)      2.)  A second XY plot.
 * 31)      3.)  An XY plot that merges the plots in 1.) and 2.).
 * 32)      4.)  The same thing as in 3.) accomplished by making the
 * 33)           second XY plot and annotation to the first.
 * 34)      5.)  The plot in 4.) with the annotation removed, reproducing
 * 35)           the plot in 1.).
 * 36)  Notes:
 * 1)      2.)  A second XY plot.
 * 2)      3.)  An XY plot that merges the plots in 1.) and 2.).
 * 3)      4.)  The same thing as in 3.) accomplished by making the
 * 4)           second XY plot and annotation to the first.
 * 5)      5.)  The plot in 4.) with the annotation removed, reproducing
 * 6)           the plot in 1.).
 * 7)  Notes:
 * 1)  Notes:

import Ngl
 * 1)  Import Ngl support functions.
 * 1)  Import Ngl support functions.

dirc    = Ngl.pynglpath("data") data    = Ngl.asciiread(dirc+"/asc/xy.asc",[516],"float")
 * 1)  xy.asc has 4 vars of length 129 longitudes, u, v, and t.
 * 2)  The data is taken at 43N latitude.  Longitude is an index
 * 3)  1-129 standing for 0 deg - 360 deg in steps of 360/128.
 * 4)  u and v are in m/s, and t is in deg K.
 * 1)  1-129 standing for 0 deg - 360 deg in steps of 360/128.
 * 2)  u and v are in m/s, and t is in deg K.

lon = data[0:512:4]    # First column of data is longitude. u   = data[1:513:4]    # Second column is u v    = data[2:514:4]    # Third column is v (not used in this example) t   = data[3:515:4]    # Fourth column is t

lon = (lon-1.) * 360./128. t  = (t-273.15) * 9./5. + 32.

wks_type = "ps" wks = Ngl.open_wks(wks_type,"multi_y")
 * 1) Open a workstation.
 * 1) Open a workstation.

res1 = Ngl.Resources res2 = Ngl.Resources
 * 1) Set up two separate resource lists, since we'll be creating two
 * 2) different XY plots.
 * 1) different XY plots.


 * 1) Don't maximize the plot in the frame, because we are controlling the
 * 2) size and location of both plots with the vpXXX resources.
 * 1) size and location of both plots with the vpXXX resources.

res1.nglMaximize = False res1.vpHeightF  = 0.75 res1.vpWidthF   = 0.65 res1.vpXF       = 0.20 res1.vpYF       = 0.90

res1.tiMainString    = "First plot" res1.tiYAxisString   = "Temperature in C~S~o~N~" res1.tiXAxisString   = "Longitude (degrees)" res1.tiYAxisFontColor = "red"
 * 1) Set some axis strings, including the main title.
 * 1) Set some axis strings, including the main title.

res1.xyLineColor     = "red" res1.xyLineThicknessF = 2.0
 * 1) Change line color and thickness.
 * 1) Change line color and thickness.

res1.trXMinF    =   0. res1.trXMaxF    =  360. res1.trYMinF    =  -80. res1.trYMaxF    =  -55. res1.trYReverse = False
 * 1) Set the actual limits of the X and Y axes.
 * 1) Set the actual limits of the X and Y axes.

res1.tmYLMode    = "Explicit" res1.tmYLValues  = [ -80., -75., -70., -65., -60., -55.] res1.tmYLLabels  = ["-80","-75","-70","-65","-60","-55"] res1.tmYUseLeft  = False res1.tmYROn      = False res1.tmYRMinorOn = False res1.tmXBMinorOn = False
 * 1) Set some tickmark resources. Turn off the right tickmarks completely.
 * 2) Label the left tickmarks with values we choose.
 * 1) Label the left tickmarks with values we choose.

plot1 = Ngl.xy(wks,lon,t,res1)
 * 1) Create and draw the first plot.  If you don't want this
 * 2) plot drawn, set:
 * 3) res1.nglDraw  = False
 * 4) res1.nglFrame = False
 * 1) res1.nglDraw  = False
 * 2) res1.nglFrame = False

res2.nglMaximize = False res2.vpHeightF  = res1.vpHeightF res2.vpWidthF   = res1.vpWidthF res2.vpXF       = res1.vpXF res2.vpYF       = res1.vpYF
 * 1) Define resources for second plot.
 * 2) There is no need to maximize the second plot either, because we
 * 3) are using the same size as the first plot.
 * 1) There is no need to maximize the second plot either, because we
 * 2) are using the same size as the first plot.

res2.trXMinF = res1.trXMinF res2.trXMaxF = res1.trXMaxF res2.trYMaxF = 60. res2.trYMinF = 10.
 * 1) Since the two plots share the same X data, the two trX**** resources
 * 2) make sure the X axis limits are the same for the second plot.
 * 1) make sure the X axis limits are the same for the second plot.

res2.tmXBOn      = False res2.tmXBLabelsOn = False res2.tmXBMinorOn = False res2.tmYLOn      = False res2.tmYLLabelsOn = False res2.tmYLMinorOn = False
 * 1) Turn off the bottom and left tickmarks, since we will use the ones from
 * 2) the first plot.
 * 1) the first plot.

res2.tmYRLabelsOn = True res2.tmYROn      = True res2.tmYUseLeft  = False res2.tmYRFormat  = "f"      # Gets rid of unnecessary trailing zeros
 * 1) Turn on the right Y labels and tickmarks and move the axis string to
 * 2) the right.
 * 1) the right.

res2.tiYAxisString     = "U component of wind (m/s)" res2.tiYAxisSide       = "Right" res2.tiYAxisFontColor  = "purple" res2.tiXAxisFontHeightF = Ngl.get_float(plot1,"tiXAxisFontHeightF")
 * 1) Move the Y axis string to the right.
 * 1) Move the Y axis string to the right.

res2.tmYRLabelFontHeightF = Ngl.get_float(plot1,"tmYLLabelFontHeightF") res2.tmYRMajorLengthF    = Ngl.get_float(plot1,"tmYLMajorLengthF")
 * 1) Make sure the font heights and tickmark lengths are the same as
 * 2) the first plot.
 * 1) the first plot.

pattern = "$_____$_____$$_____$$_____$$_____$$_____$$___" res2.xyDashPattern   = Ngl.new_dash_pattern(wks,pattern) res2.xyLineColor     = "purple" res2.xyLineThicknessF = 3.0
 * 1) Change line pattern, color and thickness.
 * 1) Change line pattern, color and thickness.

res2.tiMainString    = "Second plot"
 * 1) Main title.
 * 1) Main title.

plot2 = Ngl.xy(wks,lon,u,res2)
 * 1) Create and draw the first plot.  If you don't want this
 * 2) plot drawn, set:
 * 3) res2.nglDraw  = False
 * 4) res2.nglFrame = False
 * 1) res2.nglDraw  = False
 * 2) res2.nglFrame = False

sres             = Ngl.Resources sres.tiMainString = "Two variables with individual scales" Ngl.set_values(plot1,sres)
 * 1) Now, draw the two plots and advance the frame. Since we went through
 * 2) all the trouble to make sure the plots were in the same location,
 * 3) and that the appropriate tickmarks were turned off in certain areas,
 * 4) these two plots should look like one plot, but with two separate
 * 5) curves and two separate Y axes.
 * 6) Also, change the main title of the first plot to reflect that
 * 7) we have two vars here, and remove the main title from the second plot.
 * 1) Also, change the main title of the first plot to reflect that
 * 2) we have two vars here, and remove the main title from the second plot.

sres         = Ngl.Resources sres.tiMainOn = False Ngl.set_values(plot2,sres)

Ngl.draw(plot1) Ngl.draw(plot2) Ngl.frame(wks)

sres               = Ngl.Resources sres.amZone        = 0     # '0' means centered over base plot. sres.amResizeNotify = True anno = Ngl.add_annotation(plot1,plot2,sres)
 * 1) Just to show it can be done, add the second plot as an annotation
 * 2) of the first plot.
 * 1) of the first plot.

sres             = Ngl.Resources sres.tiMainString = "One plot added as annotation of another" Ngl.set_values(plot1,sres)
 * 1) Change the main title to reflect this is an added annotation.
 * 1) Change the main title to reflect this is an added annotation.

Ngl.draw(plot1) Ngl.frame(wks)
 * 1) Now if you draw plot1, and plot2 will be drawn automatically.  Also,
 * 2) if you resize plot1, the attached plot2 will resize automatically.
 * 1) if you resize plot1, the attached plot2 will resize automatically.

Ngl.remove_annotation(plot1,anno)
 * 1) Show how Ngl.remove_annotation works.
 * 1) Show how Ngl.remove_annotation works.

sres             = Ngl.Resources sres.tiMainString = "Annotation removed, back to original first plot" Ngl.set_values(plot1,sres)
 * 1) Change the main title to reflect that an annotation has been removed.
 * 1) Change the main title to reflect that an annotation has been removed.

Ngl.draw(plot1) Ngl.frame(wks)

Ngl.end

code ejemplo2: colores

Codigo en Python: code File:
 * 1)    color1.py
 * 2)  Synopsis:
 * 3)    Draws all colors in user specified color maps.
 * 4)  Category:
 * 5)    Colors
 * 6)  Author:
 * 7)    Mary Haley
 * 8)  Date of initial publication:
 * 9)    December, 2004
 * 10)  Description:
 * 11)    Loop through a list of color map names and
 * 12)    draw the maps as a table of colors and index
 * 13)    values.  By uncommenting designated sections
 * 14)    of the code all available color maps can be drawn.
 * 15)    Note that PyNGL internally sets the background and
 * 16)    foreground colors to white and black respectively. If
 * 17)    you want to change this, you will need to set the
 * 18)    resources wkBackgroundColor and wkForegroundColor when
 * 19)    you create the workstation.
 * 20)  Effects illustrated:
 * 21)    Changing color maps in a loop.
 * 22)  Output:
 * 23)    By default, three color maps are drawn.
 * 24)  Notes:
 * 25)    If you decide to draw *all* color maps and are writing
 * 26)    to a PS, PDF, or an NCGM file, then those files will be
 * 27)    quite large (approxmately 20MB for PS; 30MB for PDF;
 * 28)    8 MB for NCGM).
 * 1)  Output:
 * 2)    By default, three color maps are drawn.
 * 3)  Notes:
 * 4)    If you decide to draw *all* color maps and are writing
 * 5)    to a PS, PDF, or an NCGM file, then those files will be
 * 6)    quite large (approxmately 20MB for PS; 30MB for PDF;
 * 7)    8 MB for NCGM).
 * 1)    8 MB for NCGM).

import Ngl import os, sys

wks_type = "ps" wks = Ngl.open_wks(wks_type,"color1")

rlist = Ngl.Resources

color_files = ["thelix","GreenYellow","gsltod"]
 * 1)  Specify a list of color map names.
 * 1)  Specify a list of color map names.


 * 1)  If you want to draw *all* color maps, uncomment the following
 * 2)  lines (delete the initial "#" only in order to preserve proper
 * 3)  indentation).
 * 4) pkgs_pth   = os.path.join(sys.prefix, 'lib', 'python'+sys.version[:3],
 * 5)                          'site-packages')
 * 6) color_dir  = pkgs_pth + "/PyNGL/ncarg/colormaps"
 * 7) color_files = os.listdir(color_dir)
 * 1) color_dir  = pkgs_pth + "/PyNGL/ncarg/colormaps"
 * 2) color_files = os.listdir(color_dir)

for i in xrange(len(color_files)): rlist.wkColorMap = color_files[i]
 * 1)  If you want to draw all color maps uncomment the following
 * 2)  three lines (replace the initial "#" with a space in order to
 * 3)  preserve proper indentation).
 * 4) base_name = os.path.splitext(color_files[i])
 * 5) print base_name[0]
 * 6) rlist.wkColorMap = base_name[0]
 * 1) print base_name[0]
 * 2) rlist.wkColorMap = base_name[0]

Ngl.set_values(wks,rlist) Ngl.draw_colormap(wks)
 * 1)  Set the color map and draw it.  The draw call automatically
 * 2)  advances the frame.
 * 1)  advances the frame.

Ngl.end

code Ejemplo3: contornos



codigo en Python: code File: import Ngl import numpy
 * 1)     cn01p.py
 * 2)   Synopsis:
 * 3)     Draws a simple contour using all defaults.
 * 4)   Category:
 * 5)     Contouring
 * 6)   Author:
 * 7)     Fred Clare (based on an example of Dave Brown)
 * 8)   Date of initial publication:
 * 9)     November, 2004
 * 10)   Description:
 * 11)     Given a simple mathematically generated data set,
 * 12)     demonstrates Ngl.contour with all resources set
 * 13)     to their defaults.
 * 14)  Effects illustrated:
 * 15)     Drawing a contour visualization using all defaults.
 * 16)  Output:
 * 17)     A single visualization is produced.
 * 1)     to their defaults.
 * 2)  Effects illustrated:
 * 3)     Drawing a contour visualization using all defaults.
 * 4)  Output:
 * 5)     A single visualization is produced.
 * 1)  Output:
 * 2)     A single visualization is produced.

M=29 N=25 T = numpy.zeros([N,M])

jspn = numpy.power(xrange(-M/2+5,M/2+5),2) ispn = numpy.power(xrange(-N/2-3,N/2-3),2) for i in xrange(len(ispn)): T[i,:] = ispn[i] + jspn T = 100. - 8.*numpy.sqrt(T)
 * 1) create a mound as a test data set
 * 1) create a mound as a test data set

wks_type = "ps" wks = Ngl.open_wks(wks_type,"cn01p") Ngl.contour(wks,T)
 * 1)  Open a workstation and draw the contour plot.
 * 1)  Open a workstation and draw the contour plot.

Ngl.end

code Ejemplo 4: contornos de figuras irregulares codigo en Python: code
 * 1)  File:
 * 2)    chkbay.py
 * 3)  Synopsis:
 * 4)    Draws contours on a triangular mesh.
 * 5)  Category:
 * 6)    Contouring
 * 7)  Author:
 * 8)    Mary Haley
 * 9)  Date of initial publication:
 * 10)    September, 2004
 * 11)  Description:
 * 12)    This example reads data defined on a triangular
 * 13)    mesh and creates colored contour visualizations of
 * 14)    the depth of water in the Chesapeake Bay.
 * 15)  Effects illustrated:
 * 16)    o  Reading from a NetCDF file using Nio.
 * 17)    o  Using a named color table.
 * 18)    o  How to spread colors evenly over a
 * 19)         subset of a color table.
 * 20)    o  Using a cylindrical equidistant map projection.
 * 21)    o  How to select a map database resolution.
 * 22)    o  How to use function codes in text strings.
 * 23)  Output:
 * 24)    Two visualizations are produced, the first
 * 25)    is a simple contour of the depth field and the
 * 26)    second overlays that contour on a map of the
 * 27)    Chesapeake Bay.
 * 28)  Notes:
 * 29)    1.)  The grid definition and data came from the
 * 30)         Chesapeake Community Model Program Quoddy model:
 * 31)            http://ccmp.chesapeake.org
 * 32)         using the NOAA/NOS standardized hydrodynamic
 * 33)         model NetCDF format:
 * 34)            https://sourceforge.net/projects/oceanmodelfiles
 * 35)    2.)  If you want high resolution map coastlines you will
 * 36)         need to download the appropriate data files, if you
 * 37)         have not done so.  For details, see:
 * 38)            http://www.pyngl.ucar.edu/Graphics/rangs.shtml
 * 1)            http://ccmp.chesapeake.org
 * 2)         using the NOAA/NOS standardized hydrodynamic
 * 3)         model NetCDF format:
 * 4)            https://sourceforge.net/projects/oceanmodelfiles
 * 5)    2.)  If you want high resolution map coastlines you will
 * 6)         need to download the appropriate data files, if you
 * 7)         have not done so.  For details, see:
 * 8)            http://www.pyngl.ucar.edu/Graphics/rangs.shtml
 * 1)    2.)  If you want high resolution map coastlines you will
 * 2)         need to download the appropriate data files, if you
 * 3)         have not done so.  For details, see:
 * 4)            http://www.pyngl.ucar.edu/Graphics/rangs.shtml
 * 1)            http://www.pyngl.ucar.edu/Graphics/rangs.shtml

import numpy
 * 1)  Import numpy.
 * 1)  Import numpy.

import Ngl
 * 1)  Import Ngl support functions.
 * 1)  Import Ngl support functions.

import Nio
 * 1)  Import Nio for reading netCDF files.
 * 1)  Import Nio for reading netCDF files.

dirc = Ngl.pynglpath("data") cfile = Nio.open_file(dirc + "/cdf/ctcbay.nc","r")

lat  = cfile.variables["lat"][:] lon  = cfile.variables["lon"][:] ele  = cfile.variables["ele"][:] depth = cfile.variables["depth"][:]
 * 1)  Read the lat/lon/ele/depth arrays to numpy.arrays.
 * 1)  Read the lat/lon/ele/depth arrays to numpy.arrays.

rlist           = Ngl.Resources rlist.wkColorMap = "rainbow+gray" wks_type = "ps" wks = Ngl.open_wks(wks_type,"chkbay",rlist)
 * 1)  Select a colormap and open a PostScript workstation.
 * 1)  Select a colormap and open a PostScript workstation.

resources = Ngl.Resources
 * 1)  The next set of resources will apply to the contour plot.
 * 1)  The next set of resources will apply to the contour plot.

resources.nglSpreadColorStart = 15 resources.nglSpreadColorEnd  = -2

resources.sfXArray        = lon  # Portion of map on which to overlay resources.sfYArray        = lat  # contour plot. resources.sfElementNodes  = ele resources.sfFirstNodeIndex = 1

resources.cnFillOn        = True resources.cnLinesOn       = False resources.cnLineLabelsOn  = False

contour = Ngl.contour(wks,depth,resources)
 * 1) This plot isn't very interesting because it isn't overlaid on a map.
 * 2) We are only creating it so we can retrieve information that we need
 * 3) to overlay it on a map plot later. You can turn off this plot
 * 4) by setting the nglDraw and nglFrame resources to False.
 * 1) by setting the nglDraw and nglFrame resources to False.

resources.mpProjection = "CylindricalEquidistant"
 * 1)  The next set of resources will apply to the map plot.
 * 1)  The next set of resources will apply to the map plot.

resources.mpDataBaseVersion = "MediumRes"
 * 1) Once the high resolution coastline data files have been
 * 2) downloaded (see the Notes section above for details), to
 * 3) access them you need to change the following resource
 * 4) to "HighRes".
 * 1) to "HighRes".

xs = Ngl.get_float(contour.sffield,"sfXCActualStartF") xe = Ngl.get_float(contour.sffield,"sfXCActualEndF") ys = Ngl.get_float(contour.sffield,"sfYCActualStartF") ye = Ngl.get_float(contour.sffield,"sfYCActualEndF")
 * 1) Retrieve the actual lat/lon end points of the scalar array so
 * 2) we know where to overlay on map.
 * 1) we know where to overlay on map.

resources.mpLimitMode          = "LatLon" resources.mpMinLonF            = xs     # -77.3244 resources.mpMaxLonF            = xe     # -75.5304 resources.mpMinLatF            = ys     #  36.6342 resources.mpMaxLatF            = ye     #  39.6212


 * 1) In PyNGL, the "~" character represents a function code. A function
 * 2) code signals an operation you want to apply to the following text.
 * 3) In this case, ~H10Q~ inserts 10 horizontal spaces before the text,
 * 4) and ~C~ causes a line feed (carriage return).
 * 1) and ~C~ causes a line feed (carriage return).

resources.tiMainString      = "~H10Q~Chesapeake Bay~C~Bathymetry~H16Q~meters" resources.lbLabelFontHeightF = 0.02

map = Ngl.contour_map(wks,depth,resources)

Ngl.end

code Ejemplo 5: labels code
 * 1)  File:
 * 2)    labelbar.py
 * 3)  Synopsis:
 * 4)    Demonstrates labelbars and labelbar resource settings.
 * 5)  Category:
 * 6)    Labelbar
 * 7)  Author:
 * 8)    Mary Haley
 * 9)  Date of initial publication:
 * 10)    March, 2005
 * 11)  Description:
 * 12)    This example illustrates the effects of setting values
 * 13)    for various labelbar resources.
 * 14)  Effects illustrated:
 * 15)    Labelbar fonts, sizes, orientation, alignment, and fill patterns.
 * 16)  Output:
 * 17)    Four labelbar visualizations are produced showing:
 * 18)      1.) default settings
 * 19)      2.) changing the font and alignment
 * 20)      3.) changing the size, orientation and fill pattern
 * 21)      4.) using lots of user-specified labels
 * 22)  Notes:
 * 1)  Output:
 * 2)    Four labelbar visualizations are produced showing:
 * 3)      1.) default settings
 * 4)      2.) changing the font and alignment
 * 5)      3.) changing the size, orientation and fill pattern
 * 6)      4.) using lots of user-specified labels
 * 7)  Notes:
 * 1)  Notes:

import Ngl
 * 1)  Import Ngl support functions.
 * 1)  Import Ngl support functions.

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

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

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

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

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

del rlist.lbLabelFont rlist.vpWidthF         = 0.85 rlist.vpHeightF        = 0.20 rlist.lbMonoFillPattern = 21 rlist.lbFillPattern    = "SolidFill" rlist.lbOrientation    = "Horizontal" rlist.lbLabelAlignment = "ExternalEdges" lb = Ngl.labelbar_ndc(wks,5,labels,0.1,0.2,rlist) Ngl.frame(wks)
 * 1) Change the size, orientation, the fill to solid fill.
 * 1) Change the size, orientation, the fill to solid fill.


 * 1) Do a lot of labels. Notice how the labelbar labels are automatically
 * 2) adjusted and not every one is shown. To turn this off, set
 * 3) lbAutoStride to False, but then your labels will run into each other.
 * 4) You could set lbLabelAngleF to -45 or 90 to get slanted labels.
 * 1) You could set lbLabelAngleF to -45 or 90 to get slanted labels.

lotta_labels = ["AL","AR","AZ","CA","CO","CT","DE","FL","GA","IA","ID","IL",\ "IN","KS","KY","LA","MA","MD","ME","MI","MN","MO","MS","MT",\ "NC","ND","NE","NH","NJ","NM","NV","NY","OH","OK","OR","PA",\ "RI","SC","SD","TN","TX","UT","VA","VT","WA","WI","WV","WY"]

rlist.lbLabelAlignment  = "InteriorEdges" rlist.lbLabelFontHeightF = 0.014 lb = Ngl.labelbar_ndc(wks,len(lotta_labels),lotta_labels,0.1,0.5,rlist) Ngl.frame(wks)

Ngl.end

code Ejemplo 6: legendas code
 * 1)  File:
 * 2)    legend.py
 * 3)  Synopsis:
 * 4)    Demonstrates legends and legend resource settings.
 * 5)  Category:
 * 6)    Legend
 * 7)  Author:
 * 8)    Mary Haley
 * 9)  Date of initial publication:
 * 10)    March, 2005
 * 11)  Description:
 * 12)    This example illustrates the effects of setting values
 * 13)    for various legend resources.
 * 14)  Effects illustrated:
 * 15)    Legend fonts, sizes, and orientation.
 * 16)  Output:
 * 17)    Four labelbar visualizations are produced showing:
 * 18)      1.) default settings
 * 19)      2.) changing the label font
 * 20)      3.) changing the size and orientation
 * 21)      4.) using lots of user-specified labels
 * 22)  Notes:
 * 1)  Output:
 * 2)    Four labelbar visualizations are produced showing:
 * 3)      1.) default settings
 * 4)      2.) changing the label font
 * 5)      3.) changing the size and orientation
 * 6)      4.) using lots of user-specified labels
 * 7)  Notes:
 * 1)  Notes:

import Ngl
 * 1)  Import Ngl support functions.
 * 1)  Import Ngl support functions.

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

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

lg = Ngl.legend_ndc(wks,5,labels,0.3,0.9) Ngl.frame(wks)
 * 1) Generate a legend with the default settings.
 * 1) Generate a legend with the default settings.

rlist                 = Ngl.Resources rlist.lgLineThicknessF = 4.0 rlist.lgLabelFont     = "Times-bold"
 * 1) Change the font and line thickness of the labels.
 * 1) Change the font and line thickness of the labels.

lg = Ngl.legend_ndc(wks,5,labels,0.3,0.9,rlist) Ngl.frame(wks)

del rlist.lgLabelFont rlist.vpWidthF         = 0.85 rlist.vpHeightF        = 0.20 rlist.lgOrientation    = "Horizontal" lg = Ngl.legend_ndc(wks,6,labels,0.1,0.2,rlist) Ngl.frame(wks)
 * 1) Change the orientation and size.
 * 1) Change the orientation and size.


 * 1) Generate a lot of labels. Notice how the legend labels are automatically
 * 2) adjusted and not every one is shown. To turn this off, set
 * 3) lgAutoStride to False, but then your labels will run into each other.
 * 4) You could set lgLabelAngleF to -45 or 90 to get slanted labels.
 * 1) You could set lgLabelAngleF to -45 or 90 to get slanted labels.

lotta_labels = ["AL","AR","AZ","CA","CO","CT","DE","FL","GA","IA","ID","IL",\ "IN","KS","KY","LA","MA","MD","ME","MI","MN","MO","MS","MT",\ "NC","ND","NE","NH","NJ","NM","NV","NY","OH","OK","OR","PA",\ "RI","SC","SD","TN","TX","UT","VA","VT","WA","WI","WV","WY"]

rlist.lgLabelAlignment  = "AboveItems" rlist.lgLabelFontHeightF = 0.014 rlist.lgMonoDashIndex   = True lg = Ngl.legend_ndc(wks,len(lotta_labels),lotta_labels,0.1,0.5,rlist) Ngl.frame(wks)

Ngl.end

code Otros ejemplos: puedes visistar la pagina oficial http://www.pyngl.ucar.edu/Examples/gallery.shtml en donde encontraras mas variedad de ejemplos