Re: combined bar plot (distribution diagram)

From: Adam Phillips <asphilli_at_nyahnyahspammersnyahnyah>
Date: Wed Jun 04 2014 - 10:40:29 MDT

Hi Erika,
As a reminder: pdfx is a contributed function, so you can always look at
the underlying code by examining the contributed file itself:
$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl
If the code doesn't exactly do what you want you can always modify the
code by copying and renaming a particular function.

You are right, you cannot exactly specify the bin-centers in pdfx.
However, looking at the coding for pdfx, there's this:
if (opt .and. isatt(opt,"bin_min")) then
       xMin = opt@bin_min ; user set
   else
       xMin = XMIN ; calculate
   end if

   if (opt .and. isatt(opt,"bin_max")) then
       xMax = opt@bin_max ; user set
   else
       xMax = XMAX ; calculate
   end if

; skip ahead in code

   dbin = (xMax-xMin)/nbins
   binBound = xMin + ispan(0,nbins,1)*dbin
   binBound(nbins) = xMax ; avoid roundoff
   binCenter = (binBound(0:nbins-1) + binBound(1:nbins))*0.5d

What this shows is that you can indirectly set the bin centers by
specifying the same
bin_max, bin_min, and the number of bins. Notice that this will be
scalable. Setting bin_min to -20 and bin_max to 20 and the number of
bins to 20 means binCenter will be = ispan(-19,19,2). While setting
bin_min to -40 and bin_max to 40 and the number of bins to 40 means
binCenter will be = ispan(-39,39,2).

So you can get the bin centers to be the same. As far as shifting the
bars in gsn_csm_xy: That's just a matter of shifting the input x-axis
array(s) in gsn_csm_xy.. In the example I sent yesterday, assuming now
that the bin centers are all the same you could do this:

width = (xx(0,2) - xx(0,1))/2.5 ; If the bin centers are the same the
bin widths are the same for all of xx.
res@gsnXYBarChartBarWidth = width
plot = gsn_csm_xy (wks, xx(0,:)-(width*1.2), yy(0,:), res)
plot2 = gsn_csm_xy (wks, xx(1,:), yy(1,:), res)
plot3 = gsn_csm_xy (wks, xx(2,:)+(width*1.2), yy(2,:), res)

Obviously you might have to adjust the (width*1.2) syntax along with the
calculation of width for your own needs.
Hope that helps, and if not, let ncl-talk know..
Adam

On 06/04/2014 09:56 AM, Erika Folova wrote:
> Dear NCL,
>
> Adam, thanks,,
> I tried to do it again as your suggestion. The plot is attached,
> I think I still have a problem, as you can see where the bar charts
> are still overlapped, is there any trick
> how to manage this, at least to shift the overlapping bar?
>
> I am really sure, this issue comes from the pdfx function, where the
> "bin centers" are different from these
> 3 distribution, is there any way around how to solve this proble, I
> just want at least get the bar attached one to another.
> Thanks for your help. Regards.
>
>
> On Wed, Jun 4, 2014 at 5:08 AM, Adam Phillips <asphilli@ucar.edu
> <mailto:asphilli@ucar.edu>> wrote:
>
> Hi Erika,
> There's two things going on here:
> 1) The bin centers for your three bar charts are all different and
> each bar chart has different bin sizes. This makes lining them up
> in a nice fashion nearly impossible.
> 2) res@gsnXYBarChartColors does not work the way you are trying to
> use it. It applies the colors set in res@gsnXYBarChartColors
> sequentially to each bin. Thus, setting res@gsnXYBarChartColors =
> (/"orange","red","black"/) will set the first bar of your first
> bar chart orange, the second bar red, the third bar black, the
> fourth bar orange and so on. It will not set the first bar chart
> entirely to orange, the second to red, and the third to black.
>
> Take a look at example #9 here:
> http://www.ncl.ucar.edu/Applications/bar.shtml#ex9
>
> Note that the input x-axis values differ for each bar chart when
> each of the four plots is created.
>
> Also note that gsn_labelbar_ndc is used to create the labelbar,
> and that's the way I would recommend creating the legend using
> this method. I have attached a modified version of your script
> along with the resulting plot. I did not add coding to put the
> legend in.
>
> Hope that helps. If you have any further questions please reply to
> ncl-talk.
> Adam
>
>
> On 06/03/2014 12:41 PM, Erika Folova wrote:
>> Hallo NCL,
>>
>> Lately Im trying to generate a plot by combining three
>> distributions (bar chart) from the output of pdf function.
>> The figure that I want to have is attached (expected_figure.png).
>> I experimented to try it using a simple script provided in
>> example 2, but when i turn on the barchart options it seems like
>> all the bars are overlapped.
>> Is there any nice trick to do this kind of task (output of pdf
>> function) ? I really appreciate for your nice help
>>
>> Best.
>> Erika
>>
>>
>> _______________________________________________
>> ncl-talk mailing list
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
> --
> ______________________________________________________________
> Adam Phillipsasphilli@ucar.edu <mailto:asphilli@ucar.edu>
> NCAR/Climate and Global Dynamics Division(303) 497-1726 <tel:%28303%29%20497-1726>
> P.O. Box 3000
> Boulder, CO 80307-3000http://www.cgd.ucar.edu/staff/asphilli
>
>

-- 
______________________________________________________________
Adam Phillips                                asphilli@ucar.edu
NCAR/Climate and Global Dynamics Division       (303) 497-1726
P.O. Box 3000				
Boulder, CO 80307-3000    http://www.cgd.ucar.edu/staff/asphilli

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Wed Jun 04 10:40:42 2014

This archive was generated by hypermail 2.1.8 : Sat Jun 07 2014 - 11:03:12 MDT