Re: more questions

From: David Brown <dbrown_at_nyahnyahspammersnyahnyah>
Date: Fri, 5 Nov 2004 12:25:57 -0700

See below.
On Nov 4, 2004, at 4:32 PM, Mary Haley wrote:

>>
>> Hello everyone,
>>
>> I also have some questions regarding plotting with PyNGL:
>>
>> 1. I make lots of similar plots/maps that use the same settings for
>> several resources. Is there a way to specify a "resource file" with
>> the common resource settings that can be used in several different
>> Python scripts?
>
> Hi Ivan,
>
> Yes, you can use a resource file called ".hluresfile" that you put in
> your home directory. Note that you cannot set the "ngl" resources in
> this file.
>
> So, for example, if you always want a white background, black
> foreground, helvetica font, a function code of "~" (the default is a
> colon, which is a common character in titles), and a size of 700x700
> whenever you send your output to an X11 window, you would create a
> file called "~/.hluresfile", and put the following six lines in it:
>
> *wkForegroundColor : (/0.,0.,0./)
> *wkBackgroundColor : (/1.,1.,1./)
> *Font : helvetica
> *txFuncCode : ~
> *wkWidth : 700
> *wkHeight : 700
>
> There is more information about resource files in the PyNGL document:
>
> http://www.pyngl.ucar.edu/selectedtopics.html#ResourceFiles
>
>> 2. Is there a way to change the view port size (vpWidthF or
>> vpHeightF) but keep the X and Y axis labels the same size?
>
> Whenever you change the width and height of your plot, other aspects
> of the plot (including the X/Y axis labels) will scale accordingly.
> To fix the size of these labels, you need to set them explicitly:
>
> resources.tiXAxisFontHeightF = 0.025
> resources.tiYAxisFontHeightF = 0.025
>
> If you want to retrieve the font heights from your current plot so you
> know what to set them to before you change the size, add the following
> lines after your plot is created:
>
> ...
> contour = Ngl.contour(wks,data,resources)
> ...
> ysize = Ngl.get_float(contour.base,"tiYAxisFontHeightF")
> xsize = Ngl.get_float(contour.base,"tiXAxisFontHeightF")
> print xsize, ysize
>
> Then, use the values for xsize and ysize to set your font heights.
>
>> 3. How do I make the labelbar legends that are smaller than one to
>> be in the format "0.1" instead of ".1"?
>
> For some of our text resources, like the tickmark labels, we have a
> corresponding "Format" resource that allows you to format the strings
> used. However, I don't see a similar resource for labelbar
> labels. I'm not sure if this is an oversight, or if it just hasn't
> been implemented. [Dave B, can you pipe in here?]

It's true that the LabelBar does not have a resource of it's own for
controlling
the formatting of numbers. That is because with respect to the LabelBar
itself, the
labels are explicitly set using a string resource and it does not know
anything about
their numerical significance. However, when a LabelBar is created as a
ContourPlot
annotation (speaking in OO terms here), it derives its labels from the
ContourPlot
line labels (whether or not they are displayed). Therefore the
ContourPlot line label
formatting resource, cnLineLabelFormat, determines the formatting of
the LabelBar
labels in this context.

The formatting specification is rather complex because it tries to
provide a way to
consider the whole range of numbers in a single context based on the
largest
absolute value in the sequence. It also has support for graphical
features such as
superscripts for exponents. It appears as an extension of the C
language formatting specification.

For your specific issue of ensuring that bare decimal points be padded
with a '0',
you could try modifying the default value of cnLineLabelFormat, which
is "*+^sg" , to one
of the following:

        "0@*+^sg" , "@*+^sg" , "0*+^sg".

There is an example (not using PyNGL) that shows the effects of various
formatting
options for TickMarks, called tm04n.ncl. I'm attaching its output. It
should work similarly for ContourPlots, although there is another
resource that comes into play called cnMaxDataFormat.

For the complete nitty gritty see:

http://ngwww.ucar.edu/ngdoc/ng/ref/hlu/Format.html

as well as the resource docs for cnLineLabelFormat and cnMaxDataFormat.

   -dave

>
> For a work-around, you can set the labels yourself:
>
> resources.cnExplicitLabelBarLabelsOn = True
> resources.lbLabelStrings = ["0.1","0.2","0.3",...,]
>
>> 4. Is it possible to use Ngl.panel to (for example) put one XY plot
>> and 3 filled contour maps in one frame and specify a single
>> labelbar for the filled contour maps? When I tried to do that I
>> got errors saying that the panel contained plots (the XY plot) that
>> were not consistent with a labelbar attribute.
>
> Ngl.panel should only be used for plots that are the same size. If you
> want to panel different sized plots, the best thing to do is control
> the locations and sizes yourself using the vpXF, vpYF, vpWidthF, and
> vpHeightF resources.
>
> The "meteogram.py" example script shows how to create different plots
> and put them on the same page. I believe you need the latest PyNGL
> version in order to run it. Try:
>
> pyngl meteogram
>
> and it should copy a file called "meteogram.py" in your current working
> directory, run it through Python, and create a PostScript file
> called "meteogram.ps".
>
>> I would also like to thank Mary Haley and Fred Clare for their
>> effort and for giving us the ability to do high quality graphics
>> under Python.
>>
>> - Ivan
>
> Flattery will get you everywhere! Thanks for the compliment. It
> really has been the effort of the whole NCL team to bring you these
> high-quality graphics.
>
> --Mary
>
>> --
>> Ivan Lima
>> Woods Hole Oceanographic Institution, MC&G MS #25
>> 360 Woods Hole Road, Woods Hole, MA 02543-1543 USA
>> _______________________________________________
>> pyngl-talk mailing list
>> pyngl-talk_at_ucar.edu
>> http://mailman.ucar.edu/mailman/listinfo/pyngl-talk
>>
>
>
> --
> -------------------------------------------------
> Mary Haley haley_at_ucar.edu
> NCAR/SCD/VETS 303-497-1254 (voice)
> 1850 Table Mesa Dr 303-497-1804 (fax)
> Boulder, CO 80305
> -------------------------------------------------
> _______________________________________________
> pyngl-talk mailing list
> pyngl-talk_at_ucar.edu
> http://mailman.ucar.edu/mailman/listinfo/pyngl-talk

Received on Fri Nov 05 2004 - 12:26:08 MST

This archive was generated by hypermail 2.2.0 : Thu Jan 19 2006 - 21:30:17 MST