[ncl-talk] How to change color bar for the second field using gsnHistogramCompare
Mary Haley
haley at ucar.edu
Tue May 17 15:14:57 MDT 2016
As I attempted to fix the histogram problem, I realized there were a lot of
changes to make to some internal code to handle the different types of
color that can be input (index color, named colors, RGB colors, RGBA
colors).
I've attached a new version of "utilities.ncl" and an internal
"hist_columns" function that fixes the multiple colors issue. I included an
example code to try the fix.
Save all three scripts and then run with:
ncl histo_bar_colors.ncl
This script uses the now-fixed "gsnHistogramBarColors", in which you can
give it an array of colors whose dimensionality fits that with the number
of bars you have and whether you are doing a compare.
For example, if you have 2 sets of bars with 5 bars each, then you can
provide a 2 x 5 array of index colors, named colors, or RGB/RGBA arrays to
set the color for each bar:
colors =
(/(/"maroon4","firebrick","yellow","paleturquoise1","darksalmon"/),\
(/ "orange","forestgreen","tan3","navyblue","hotpink"/)/)
res at gsnHistogramBarColors = colors
--Mary
On Mon, May 16, 2016 at 11:10 AM, Mary Haley <haley at ucar.edu> wrote:
> Hi,
>
> The gsn_histogram code needs to be cleaned up so it can handle color
> better. I'm looking into this and hope to have a fix.
>
> The issue is trying to handle the different color types that can now come
> in:
>
> - named colors ("red", "blue")
> - indexed color (1, 3, 7)
> - RGB color
> - RGBA color
>
> Right now the code is assuming either RGB or indexed color AND it doesn't
> recognize the fact that you might have a second set of bars that you might
> want colored differently. It's not a bug, but just the way the code was
> implemented. It could be thought out better!
>
> --Mary
>
>
> On Mon, May 16, 2016 at 3:09 AM, rK Aditya <aditya.rk at gmail.com> wrote:
>
>> Dear All,
>>
>> Got it! I need to change gsn_code.ncl and introduce
>>
>> gsres at gsFillColor = fillcolor(j) manually inside do j=nbarsinbin-1,0,1.
>>
>> Cheers,
>> -r/K-
>>
>> On Mon, May 16, 2016 at 6:59 AM, rK Aditya <aditya.rk at gmail.com> wrote:
>>
>>> Dear Guilherme,
>>>
>>> Thank you for the suggestion. I tried to activate gsnXYBarChart toTrue
>>> as well, but gsnXYBarChartColors2 or gsnXYBarChartColors are not valid
>>> resources for this. I still could not change the color bar for the second
>>> field.
>>>
>>> Kindest regards,
>>> -r/K-
>>>
>>>
>>>
>>> On Mon, May 16, 2016 at 2:08 AM, Guilherme Martins <jgmsantos at gmail.com>
>>> wrote:
>>>
>>>> I'm note sure but try: gsnXYBarChartColors2 or gsnXYBarChartColors.
>>>>
>>>> Guilherme.
>>>>
>>>> Em dom, 15 de mai de 2016 às 16:11, rK Aditya <aditya.rk at gmail.com>
>>>> escreveu:
>>>>
>>>>> Dear All,
>>>>>
>>>>> I would like to compare histogram for two seasons; winter and summer.
>>>>> I use the first field for summer and put it with filled red color. But I
>>>>> could not change the color in the second field, on crosshatch pattern to
>>>>> other color, let say blue.
>>>>>
>>>>> If someone can help me?
>>>>>
>>>>> Thank you for your time.
>>>>>
>>>>> Kindest regards,
>>>>> -r/K-
>>>>>
>>>>>
>>>>> begin
>>>>> ;************************************************
>>>>> ; Generate some random data.
>>>>> ;************************************************
>>>>> x = new(1000,integer)
>>>>> y = new(1000,integer)
>>>>> do i=0,dimsizes(x)-1
>>>>> x(i) = rand()
>>>>> y(i) = rand()
>>>>> end do
>>>>> x = x/320
>>>>> y = y/320
>>>>>
>>>>> ;************************************************
>>>>> ; Set up a variable to hold both x and y.
>>>>> ;************************************************
>>>>> z = new((/2,dimsizes(x)/),integer)
>>>>> z(0,:) = x
>>>>> z(1,:) = y
>>>>> ;************************************************
>>>>> ; create plot
>>>>> ;************************************************
>>>>> wks = gsn_open_wks("png","histo") ; send graphics to
>>>>> PNG file
>>>>> gsn_define_colormap(wks,"temp1") ; choose colormap
>>>>>
>>>>> res = True ; plot mods desired
>>>>> res at gsnHistogramCompare = True
>>>>> res at gsnHistogramBinIntervals = (/25,50,75/)
>>>>> ; res at gsFillColors = (/(/"blue","red"/),(/"blue","red"/)/)
>>>>> ; res at gsFillColor=(/"blue","blue","red","red"/)
>>>>> res at gsnHistogramBarColors = (/(/"red","blue"/),(/"red","blue"/)/)
>>>>> ; res at gsnHistogramBarColors=(/"blue","blue","red","red"/)
>>>>> plot=gsn_histogram(wks,z,res) ; create histogram
>>>>> end
>>>>> [image: Inline image 1]
>>>>> _______________________________________________
>>>>> ncl-talk mailing list
>>>>> ncl-talk at ucar.edu
>>>>> List instructions, subscriber options, unsubscribe:
>>>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>>>
>>>> --
>>>>
>>>> ------------------------------------------------------------------------------------------
>>>> Dr. Guilherme Martins
>>>> Instituto Nacional de Pesquisas Espaciais (INPE)
>>>> Centro de Previsão de Tempo e Estudos Climáticos (CPTEC)
>>>> Grupo de Desenvolvimento em Assimilação de Dados (GDAD)
>>>> Telefone (INPE/CP): +55 12 3186-8551 || Celular (TIM): +55 12
>>>> 98152-8580
>>>> E-mail: guilherme.martins at inpe.br || jgmsantos at gmail.com
>>>> Skype: guilherme.martins.
>>>> Homepage: https://sites.google.com/site/jgmsantos
>>>> Currículo Lattes: http://lattes.cnpq.br/5997657584785803
>>>>
>>>> ------------------------------------------------------------------------------------------
>>>>
>>>
>>>
>>
>> _______________________________________________
>> 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/20160517/5bf52730/attachment.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: histo.png
Type: image/png
Size: 70341 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20160517/5bf52730/attachment.png
-------------- next part --------------
A non-text attachment was scrubbed...
Name: hist_columns_fix.ncl
Type: application/octet-stream
Size: 15584 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20160517/5bf52730/attachment.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: utilities_fix.ncl
Type: application/octet-stream
Size: 63054 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20160517/5bf52730/attachment-0001.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: histo_bar_colors.ncl
Type: application/octet-stream
Size: 1611 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20160517/5bf52730/attachment-0002.obj
More information about the ncl-talk
mailing list