[ncl-talk] Bar Graph/Histogram plot question

Mary Haley haley at ucar.edu
Wed May 3 11:46:35 MDT 2017


Hi Barry,

I think by making the image 7500x7500 this is almost making it too large,
and hence the perimeter starts to fade.

You might try a width/height of 2500 instead of 7500.

To increase the thickness of any line in NCL, usually there's a
yyXXXXThicknessF resource associated with it.

In the case of the tickmark border and the tickmarks themselves, you can
set:

  res at tmBorderThicknessF = 5.0
  res at tmXBMajorThicknessF = 5.0
  res at tmYLMajorThicknessF = 5.0
  res at tmXBMinorThicknessF = 5.0
  res at tmYLMinorThicknessF = 5.0

The default is 1.0, so the above will make things 5x as thick. Depending on
how big the resolution of your image is, you might need to go higher.

To increase the density and/or thickness of the fill pattern lines, you can
use "gs" resources, because these bars are filled in by using calls to
gsn_add_polygon internally.

Please see example histo_6a.ncl, which I just added. It shows how to change
various elements of a histogram plot:

http://www.ncl.ucar.edu/Applications/histo.shtml#ex6a

As for the hist_text.ncl code, I couldn't reproduce your problem.  I ran
your script and it produced a plot with text.

However, I did get a bunch of warnings like this:

warning:Argument 0 of the current function or procedure was coerced to the
appropriate type and thus will not change if the function or procedure
modifies its value

which is occurring because you are  calling "floattointeger" on a value
that is already an integer.  If you remove the "floattointeger", then the
warnings go away.

Also, you should be able to get rid of your do loops by taking advantage of
functions like "num", "where", and "ispan". For example, this loop:


  do i_int = 0,dims_obs_x-1
    if (obs_x(i_int).eq.0)then
     print("here in loop")
     sum_obs = sum_obs + 1
    end if
    if (mod_x(i_int).eq.0)then
     sum_mod = sum_mod + 1
    end if
  end do

can be rewritten as two lines:

  sum_obs = sum_obs + num(obs_x.eq.0)
  sum_mod = sum_mod + num(mod_x.eq.0)

--Mary


On Wed, Apr 26, 2017 at 7:21 AM, Barry Lynn <barry.h.lynn at gmail.com> wrote:

> Hi:
>
> I was unable to read the pdf file that I generated using my original code
> and these modifications -- although I can read the png.
>
> This is a separate problem which can be left to later.
>
> To work around this, I made pngs.
>
> However, when making a png, the secondary bars become lighter (attached),
> and I can't see the perimeter.  When making maps, I know how to change the
> perimeter, but not here.
>
> I tried to set the fill patterns, but the program didn't recognize them.
>
> So,  I am wondering:
>
> a) How to darken the perimeter.
>
> b) How to change and darken the fill pattern (of the second overlaid bars).
>
> c) And, I tried to add text, but the program just hangs up.
>
> Thank you
>
> P.S. I used the code on this page to add text.
>
> https://www.ncl.ucar.edu/Applications/Scripts/histo_16.ncl
>
> On Tue, Apr 25, 2017 at 9:22 PM, Barry Lynn <barry.h.lynn at gmail.com>
> wrote:
>
>> That is one fancy bit of programming...
>>
>> Thank you -- wonderful.
>>
>> On Tue, Apr 25, 2017 at 9:09 PM, Dennis Shea <shea at ucar.edu> wrote:
>>
>>> 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 title for your plot:
>>>>>
>>>>>   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?
>>>>>
>>>>> As an example, visit this page:
>>>>>
>>>>> 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.
>>>>>>>>
>>>>>>>> I adapted code from this page:
>>>>>>>>
>>>>>>>> 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
>>>>
>>>>
>>>
>>
>>
>> --
>> 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>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20170503/376fbd69/attachment.html 


More information about the ncl-talk mailing list