# [ncl-talk] Bar Graph/Histogram plot question

Dennis Shea shea at ucar.edu
Tue Apr 25 12:09:04 MDT 2017

```Re:  Compares two arrays. Both arrays are combined into a single array with
the first dimension equal to 2

Let x and y be 1D but of different lengths:

nx  = dimsizes(x)
ny  = dimsizes(y)
lxy = max( (/ nx,ny /) )

xy = new( (/2,lxy/), typeof(x), getVarFillValue(x))

xy(0,0:nx-1) = (/ x /)     ;   (/... /) no meta data
xy(1,0:ny-1) = (/ y /)

HTH

On Tue, Apr 25, 2017 at 11:14 AM, Barry Lynn <barry.h.lynn at gmail.com> wrote:

> Hi:
>
> I have been using example 6.
>
> However, the page says: "Compares two arrays. Both arrays are combined
> into a single array with the first dimension equal to 2,"
>
> and implies that both arrays are of the same length.
>
> In my case, they are of different lengths.
>
> Regarding the bar graphs -- I didn't see this particular page when I first
> looked for bar graphs.  However, it won't be helpful if I can't put one
> behind the other (and slightly off to the side) like you can with
> res at gsnHistogramCompare        = True
>
> Barry
>
> On Tue, Apr 25, 2017 at 7:06 PM, Mary Haley <haley at ucar.edu> wrote:
>
>> Hi Barry,
>>
>> Those numbers at the top are coming from this line, which sets the main
>>
>>   res at tiMainString = str_join(""+x,",")
>>
>> Remove or comment this line.
>>
>> In what way do you want to combine the two graphs?  Do you want the bars
>> side-by-side, or stacked?
>>
>>
>> http://www.ncl.ucar.edu/Applications/bar.shtml
>>
>> and look at:
>>
>> unique_5.ncl
>> bar_10.ncl
>> bar_15.ncl
>>
>> etc
>>
>> You can also look at the histogram page, see histo_6.ncl:
>>
>> http://www.ncl.ucar.edu/Applications/histo.shtml#ex6
>>
>> --Mary
>>
>>
>> On Tue, Apr 25, 2017 at 9:46 AM, Barry Lynn <barry.h.lynn at gmail.com>
>> wrote:
>>
>>> Hi:
>>>
>>> I followed Mary's comments to imply that the histogram function plots
>>> the number of elements within each interval.  Hence, when my obs
>>> distribution show, for example 227, I created 227 consecutive elements with
>>> the value 0, and then proceeded through the distribution.
>>>
>>> I would like to do the following:
>>>
>>> 1) remove the list of numbers at the top of each graph,
>>>
>>> 2) Combine the graphs.
>>>
>>> The typical approach doesn't work (bottom of code) because there are
>>> different numbers of x and y.
>>>
>>> Thank you for your suggestions.
>>>
>>> Barry
>>> P.S. The code runs stand alone.
>>>
>>> On Tue, Apr 25, 2017 at 12:34 AM, Mary Haley <haley at ucar.edu> wrote:
>>>
>>>> Hi Barry,
>>>>
>>>> The gsn_histogram function takes whatever "bin" values you give it, and
>>>> counts the number of values that fall in each bin, and then draws this as a
>>>> bar.
>>>>
>>>> If you don't provide any bins, then gsn_histogram will pick "nice" bins
>>>> for you.
>>>>
>>>> The binning happens such that no values are binned in more than one
>>>> interval.
>>>>
>>>> Try running the attached script.
>>>>
>>>> In the first plot, I let gsn_histogram pick the bin intervals.
>>>>
>>>> The first bin, which is from 1 to 2, will capture all values >= 1 and <
>>>> 2, the second bin counts all values >=2 and < 3 and so on.  The very last
>>>> bin, 9 to 10, will count all values >= 9 and <= 10.
>>>>
>>>> The second plot I specifically set the bin intervals that I want.
>>>>
>>>> In the third plot, instead of counting values that fall in a range, I
>>>> set an array of discrete values to explicitly count.
>>>>
>>>> Hope this helps clear things up.
>>>>
>>>> --Mary
>>>>
>>>>
>>>> On Sun, Apr 23, 2017 at 2:23 AM, Barry Lynn <barry.h.lynn at gmail.com>
>>>> wrote:
>>>>
>>>>> Hi:
>>>>>
>>>>> I have data specified as below.
>>>>>
>>>>>
>>>>> https://www.ncl.ucar.edu/Applications/histo.shtml
>>>>>
>>>>> Example # 6.
>>>>>
>>>>> I set x = "Obs" and y = "Forecast" below.
>>>>>
>>>>> The plot I get spreads the obs and forecast data on the x axis (where
>>>>> the x axis conforms to the value of each).
>>>>>
>>>>> The y axis is labeled "Frequency."
>>>>>
>>>>> However, this is not a histogram/bar graph I am familiar with.  I am
>>>>> not sure how frequency is calculated (perhaps out of the total). In any
>>>>> case, I want to plot the x axis as intervals of 0 to 100 (by 10).  I want
>>>>> the y-axis to show the values in the obs/forecasts that conform to these
>>>>> intervals.  (Kaleidagraph can do this easily, but that's not the point
>>>>> (obviously)).
>>>>>
>>>>> I see no such example of how to do this  -- even though this is often
>>>>> how bar graphs are presented.
>>>>>
>>>>> Thank you for your suggestions.
>>>>>
>>>>> Barry
>>>>>
>>>>>   z = new((/2,dimsizes(x)/),integer)
>>>>>   z(0,:) = x
>>>>>   z(1,:) = y
>>>>>
>>>>> Percent, Obs, Forecast
>>>>>
>>>>>     0    0.0,    0.0,
>>>>>
>>>>>     1  227.0,  212.2,
>>>>>
>>>>>     4  375.0,  176.7,
>>>>>
>>>>>     8  201.0,  141.1,
>>>>>
>>>>>    12   62.0,  143.2,
>>>>>
>>>>>    18   26.0,  327.5,
>>>>>
>>>>>    24    6.0,  199.5,
>>>>>
>>>>>    30    1.0,   50.2,
>>>>>
>>>>>    36    2.0,    9.4,
>>>>>
>>>>>   100    0.0,    4.0,
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Barry H. Lynn, Ph.D
>>>>> Senior Lecturer,
>>>>> The Institute of the Earth Science,
>>>>> The Hebrew University of Jerusalem,
>>>>> Givat Ram, Jerusalem 91904, Israel
>>>>> Tel: 972 547 231 170
>>>>> Fax: (972)-25662581
>>>>>
>>>>> C.E.O, Weather It Is, LTD
>>>>> Weather and Climate Focus
>>>>> http://weather-it-is.com
>>>>> Jerusalem, Israel
>>>>> Local: 02 930 9525
>>>>> Cell: 054 7 231 170
>>>>> Int-IS: x972 2 930 9525
>>>>> US 914 432 3108 <(914)%20432-3108>
>>>>>
>>>>> _______________________________________________
>>>>> ncl-talk mailing list
>>>>> ncl-talk at ucar.edu
>>>>> List instructions, subscriber options, unsubscribe:
>>>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>>>
>>>>>
>>>>
>>>
>>>
>>> --
>>> Barry H. Lynn, Ph.D
>>> Senior Lecturer,
>>> The Institute of the Earth Science,
>>> The Hebrew University of Jerusalem,
>>> Givat Ram, Jerusalem 91904, Israel
>>> Tel: 972 547 231 170
>>> Fax: (972)-25662581
>>>
>>> C.E.O, Weather It Is, LTD
>>> Weather and Climate Focus
>>> http://weather-it-is.com
>>> Jerusalem, Israel
>>> Local: 02 930 9525
>>> Cell: 054 7 231 170
>>> Int-IS: x972 2 930 9525
>>> US 914 432 3108 <(914)%20432-3108>
>>>
>>
>>
>
>
> --
> Barry H. Lynn, Ph.D
> Senior Lecturer,
> The Institute of the Earth Science,
> The Hebrew University of Jerusalem,
> Givat Ram, Jerusalem 91904, Israel
> Tel: 972 547 231 170
> Fax: (972)-25662581
>
> C.E.O, Weather It Is, LTD
> Weather and Climate Focus
> http://weather-it-is.com
> Jerusalem, Israel
> Local: 02 930 9525
> Cell: 054 7 231 170
> Int-IS: x972 2 930 9525
> US 914 432 3108 <(914)%20432-3108>
>
> _______________________________________________
> 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/20170425/67bed12b/attachment.html
```