[ncl-talk] colorbar that's part grayscale, part color?
Adam Phillips
asphilli at ucar.edu
Tue Feb 13 16:18:37 MST 2018
Hi Jared,
Good question. read_colormap_file should do what you want:
gsn_define_colormap(wks,"BlWhRe")
cmap = read_colormap_file("BlWhRe") ;---Returns a N x 4 (RGBA) array,
excluding first two colors that represent the background and foreground
....
plot = gsn_csm_contour_map(.....
getvalues plot at contour ; use plot at contour for contour plots created
using gsn_*_map, otherwise just use "plot"
"cnFillColors" : fill_colors
end getvalues
cmap2 = cmap(fill_colors-2,:)
print(cmap2)
The second to last line has fill_colors-2 syntax, as retrieving
cnFillColors using getvalues indexes the colors including the background
and foreground colors, while read_colormap_file does not.
Hope that helps!
Adam
On Tue, Feb 13, 2018 at 3:08 PM, Jared Lee <jaredlee at ucar.edu> wrote:
> Rashed: Thanks for that example! That's quite helpful.
>
> Adam: When I use getvalues plot at contour like you suggested, the
> fill_colors array is full of 30-bit integers. Is there a handy function or
> translation tool to convert those back to RGBA values and/or string color
> names, or would I have to write my own? The rgb.txt file on NCL's named
> colors page provides a way to compare named colors to RGB values, but does
> not include the corresponding 30-bit integers that would allow for quick
> string parsing and pattern matching.
>
> Jared
>
> On Tue, Feb 13, 2018 at 2:41 PM, Adam Phillips <asphilli at ucar.edu> wrote:
>
>> Hi Jared,
>> To add to Rashed's suggestions:
>> You can set cnFillColors to exactly the colors you want, via named
>> colors, indexes from a color map, or RGB or RGBA values.
>> http://www.ncl.ucar.edu/Document/Graphics/Resources/cn.shtml#cnFillColors
>>
>> See numerous examples here: (Search on the page for "cnFillColors")
>> http://www.ncl.ucar.edu/Applications/res_list.shtml
>>
>> To answer your query: You can use getvalues to return the colors used in
>> a specific plot:
>> plot = gsn_csm_contour_map(.....
>> getvalues plot at contour ; use plot at contour for contour plots
>> created using gsn_*_map, otherwise just use "plot"
>> "cnFillColors" : fill_colors
>> end getvalues
>> print(fill_colors)
>>
>> Hope that helps!
>> Adam
>>
>> On Tue, Feb 13, 2018 at 1:51 PM, Jared Lee <jaredlee at ucar.edu> wrote:
>>
>>> Hi Rashed,
>>>
>>> Thanks for the example! That method works fine if you have your
>>> threshold contour line (0ºC, say) is exactly in the middle of your set of
>>> contour lines, but not if you have different numbers of contours above and
>>> below your threshold value to split the colorbars/colormaps, unfortunately.
>>> And it also limits you to combining colormaps that would total no more than
>>> 256 colors.
>>>
>>> What I ended up doing to get a similar effect (though not explicitly
>>> blending two colormaps) was to play with cnFillPatterns and make the
>>> contour intervals below 0ºC be either cross-hatched or stippled (and
>>> cnFillScaleF changes the stipple density), as in the attached image (note
>>> that cnFillMode must be set to "AreaFill" to use fill patterns). That might
>>> be my compromise solution, at least for now.
>>>
>>> It would still be nice to be able to return the names of colors (or RBGA
>>> values) that are assigned to the various contour levels (after setting
>>> cnFillPalette to a named colormap and setting cnMinLevelValF,
>>> cnMaxLevelValF, and cnLevelSpacingF), and then explicitly supply different
>>> color names (or opacities) for some of the intervals. I'm not sure how to
>>> return the names of colors that are actually being used with a given set of
>>> contour levels, though.
>>>
>>> Jared
>>>
>>> On Mon, Feb 12, 2018 at 6:50 PM, Rashed Mahmood <rashidcomsis at gmail.com>
>>> wrote:
>>>
>>>> Hi Jared,
>>>> I think it's easy combine two color maps to get what you want. See
>>>> attached script and the figure. the input file is NCEP surface air
>>>> temperature.
>>>>
>>>> Cheers,
>>>> Rashed
>>>>
>>>>
>>>> On Mon, Feb 12, 2018 at 4:33 PM, Jared Lee <jaredlee at ucar.edu> wrote:
>>>>
>>>>> Hi all,
>>>>>
>>>>> Has anyone out there made any plots where the colorbar/colormap is
>>>>> part grayscale, part color? For example, what I'd like to do for one
>>>>> application is make some plots with a color palette like "NCV_bright," for
>>>>> instance, where temperatures below 0ºC (say) get plotted in a grayscaled
>>>>> version of the color palette, but grid cells with values above 0ºC get
>>>>> plotted with the regular full-color palette. How would I go about doing
>>>>> that? Would I have to manually replace the sub-zero part of my color
>>>>> palette with various named gray colors? Thanks for any tips or ideas!
>>>>>
>>>>> Jared
>>>>>
>>>>> --
>>>>> ===============================
>>>>> Jared A. Lee, Ph.D.
>>>>> Project Scientist I
>>>>> Research Applications Laboratory
>>>>> National Center for Atmospheric Research
>>>>> Boulder, Colorado, USA
>>>>>
>>>>> Member, AMS Planning Commission
>>>>>
>>>>> Email: jaredlee at ucar.edu (w)
>>>>> Phone: 303.497.8485 <(303)%20497-8485> (w)
>>>>> Web: https://staff.ucar.edu/users/jaredlee
>>>>> ===============================
>>>>>
>>>>> _______________________________________________
>>>>> ncl-talk mailing list
>>>>> ncl-talk at ucar.edu
>>>>> List instructions, subscriber options, unsubscribe:
>>>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>>>
>>>>>
>>>>
>>>
>>>
>>> --
>>> ===============================
>>> Jared A. Lee, Ph.D.
>>> Project Scientist I
>>> Research Applications Laboratory
>>> National Center for Atmospheric Research
>>> Boulder, Colorado, USA
>>>
>>> Member, AMS Planning Commission
>>>
>>> Email: jaredlee at ucar.edu (w)
>>> Phone: 303.497.8485 <(303)%20497-8485> (w)
>>> Web: https://staff.ucar.edu/users/jaredlee
>>> ===============================
>>>
>>> _______________________________________________
>>> ncl-talk mailing list
>>> ncl-talk at ucar.edu
>>> List instructions, subscriber options, unsubscribe:
>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>
>>>
>>
>>
>> --
>> Adam Phillips
>> Associate Scientist, Climate and Global Dynamics Laboratory, NCAR
>> www.cgd.ucar.edu/staff/asphilli/ 303-497-1726 <(303)%20497-1726>
>>
>> <http://www.cgd.ucar.edu/staff/asphilli>
>>
>
>
>
> --
> ===============================
> Jared A. Lee, Ph.D.
> Project Scientist I
> Research Applications Laboratory
> National Center for Atmospheric Research
> Boulder, Colorado, USA
>
> Member, AMS Planning Commission
>
> Email: jaredlee at ucar.edu (w)
> Phone: 303.497.8485 <(303)%20497-8485> (w)
> Web: https://staff.ucar.edu/users/jaredlee
> ===============================
>
--
Adam Phillips
Associate Scientist, Climate and Global Dynamics Laboratory, NCAR
www.cgd.ucar.edu/staff/asphilli/ 303-497-1726
<http://www.cgd.ucar.edu/staff/asphilli>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20180213/20cc6fc1/attachment-0001.html>
More information about the ncl-talk
mailing list