[ncl-talk] printing the names of colors used in legendbar of contour plot

Mary Haley haley at ucar.edu
Fri Sep 9 14:34:40 MDT 2016


To use the native projection, simply call:

 res = wrf_map_resources(f,res)

Where "f" is the return value from "addfile" of your WRF output file.

You will also need to set these two resources:

;---Necessary for contours to be overlaid correctly on WRF projection
  res at tfDoNDCOverlay       = True
  res at gsnAddCyclic         = False


Calling "wrf_map_resources" will also switch on the map boundaries, but it
may be hard to see them.  If it is, then call "print(res)" after you call
to see what values it is using for the outline colors and thicknesses and
change them as necessary.

To see some sample scripts that plot WRF both natively and in lat/lon
projections, go to:

http://www.ncl.ucar.edu/Applications/wrfgsn.shtml

The wrf_gsn_6.ncl example shows you how to change the map outlines to black
and make them thicker, since wrf_map_resources sets them to "gray" and a
very thin thickness.

--Mary

On Thu, Sep 8, 2016 at 9:07 PM, Tabish Ansari <tabishumaransari at gmail.com>
wrote:

> Hi Mary,
>
> Thanks for providing this script. I've been able to plot my required wrf
> data alongside observational station data with the same colorscale.
> However, my WRF data is on a Lambert Conformal projection but this scripts
> plots it on a cylindrical equidistant projection. I would like to plot it
> nicely on its native projection i.e., lambert conformal.
>
> I would also like to switch on the map boundaries (national and state,
> grid lines, geophysical etc.) on both the plots. Could you please help me
> do this?
>
> Thanks a lot!
>
> Tabish
>
> Tabish U Ansari
> PhD student, Lancaster Environment Center
> Lancaster Univeristy
> Bailrigg, Lancaster,
> LA1 4YW, United Kingdom
>
> On 28 August 2016 at 20:11, Mary Haley <haley at ucar.edu> wrote:
>
>> ​Hi Tabish,
>>
>> Here's a some extra information on colors in NCL:
>>
>> -------------------------------------------------------------------------
>> When you use a predefined colormap, like "rainbow" or "amwg", it is not
>> defined by named colors, by rather by RGBA quadruplets.
>>
>> RGBA arrays are N x 4 floating point arrays of values that go from 0 to
>> 1,  where the 'RGB' represents fractions of red, green, and blue, and the
>> 'A' represents the 'alpha' value which designates the opacity of the color.
>>
>> For example:
>>
>> The color (/1.0,0.,0.,1./)  represents red, because you have full red
>> (1.0), no green (0.0), no blue (0.0), and full opacity (1.0).
>>
>> The color (/0.0,1.0,0.0,1./) represents green, with full opacity.
>>
>> The color (/0.0,0.0,1.0,0.5/) represents blue, with half opacity.
>>
>> The color (/1.0,1.0,0.0,0.25/) represents yellow, with a quarter opacity.
>>
>> etc.
>>
>> In NCL, when you specify a color resource like:
>>
>>   res at gsMarkerColor = "red"
>>
>> you can use named colors, but you can also use direct RGBA values:
>>
>>   res at gsMarkerColor = (/1.,0.,0.,1./)   ; fully opaque red marker
>>
>> The nice thing about using RGBA values is it allows you to control the
>> opacity, for example:
>>
>>   res at gsMarkerColor = (/1.,0.,0.,0.25/)   ; mostly transparent red marker
>> ---------------------------------------------------------------------
>>
>> Anyway, you can mimic the colors that NCL uses in your WRF plot, by using
>> span_color_rgba.  You need to give this function the same levels that you
>> are using for the contour plot, and it will return the same colors being
>> used by the contour plot. Note, you could accomplish the same thing by
>> calling "getvalues" on the smoothed contour plot to retrieve the levels and
>> the colors.
>>
>> See the attached script, which creates a filled contour plot of SLP, and
>> then randomly grabs points from SLP to mimic an observational data set, but
>> draws these values using filled square markers.
>>
>> You can get the dataset from:
>>
>> http://www.ncl.ucar.edu/Applications/Data/cdf/wrfout_d01_
>> 2003-07-15_00:00:00
>>
>> --Mary
>>
>>
>>
>> On Sat, Aug 27, 2016 at 9:38 PM, Tabish Ansari <
>> tabishumaransari at gmail.com> wrote:
>>
>>> Hi
>>>
>>> I'm trying to compare wrf model output (contour plot) with some station
>>> data (scattered observations). I am trying to color the markers of the
>>> station data based on their values and create a similar legend bar as the
>>> wrf-contour. However, this is not very straightforward as I'm using
>>> predefined colormap for wrf-contour but have to explicitly specify the name
>>> of the color for each range in case of station data.
>>>
>>> This will be very easy if I know the exact name of each shade used in
>>> the legend bar of wrf-contour (out of the 650 named colors in NCL). Is
>>> there a way to print the names of these colors used in the legendbar?
>>>
>>> Thanks
>>>
>>> Tabish
>>>
>>> Tabish U Ansari
>>> PhD student, Lancaster Environment Center
>>> Lancaster Univeristy
>>> Bailrigg, Lancaster,
>>> LA1 4YW, United Kingdom
>>>
>>> _______________________________________________
>>> ncl-talk mailing list
>>> ncl-talk at ucar.edu
>>> List instructions, subscriber options, unsubscribe:
>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>
>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20160909/ccb2b30d/attachment.html 


More information about the ncl-talk mailing list