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

Mary Haley haley at ucar.edu
Sun Aug 28 13:11:39 MDT 2016


​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/20160828/5b0fe194/attachment-0001.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: wrf_obs.000003.png
Type: image/png
Size: 358698 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20160828/5b0fe194/attachment-0003.png 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: wrf_obs.000002.png
Type: image/png
Size: 333122 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20160828/5b0fe194/attachment-0004.png 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: wrf_obs.000001.png
Type: image/png
Size: 292553 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20160828/5b0fe194/attachment-0005.png 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: wrf_obs.ncl
Type: application/octet-stream
Size: 5396 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20160828/5b0fe194/attachment-0001.obj 


More information about the ncl-talk mailing list