[ncl-talk] Fewer questions about a Histogram Plot
Barry Lynn
barry.h.lynn at gmail.com
Tue Nov 21 10:23:56 MST 2017
Hi Mary:
That's my point. The histogram program is taking the data and binning it.
However, I've already binned the data, and the data itself already
represents the number of data points within each interval.
I am not sure if bar charts would help or not. I would need to look more
closely, but when I looked before it didn't seem to solve my problem (but I
was less experienced before).
Barry
On Tue, Nov 21, 2017 at 7:14 PM, Mary Haley <haley at ucar.edu> wrote:
> Hi Barry,
>
> I don't understand your question. When you say "I originally tried to
> just plot the data in mod_x and obs_x using the standard examples it didn't
> work." In what way did it not work? Can you provide your data and a
> script so I can see what you mean?
>
> You shouldn't need to count the values in each range because gsn_histogram
> does that for you.
>
> For example, here's a 5-line script that draws a very basic histogram.
>
> y = (/3.1,0.5,3.8,3.4,2.1,1.5,2.6,2.3,3.6,1.7/)
> wks = gsn_open_wks("png","hist")
> res = True
> res at gsnHistogramBinIntervals = (/0,1,2,3,4/)
> plot = gsn_histogram(wks,y,res)
>
> Note I used intervals of (0,1,2,3,4)
>
> You should see a histogram with four bars:
>
> First bar = 1 b/c we have one value >=0 and < 1
> Second bar = 2 b/c we have two values >=1 and < 2
> Third bar = 3 b/c we have three values >=2 and < 3
> Fourth bar = 4 b/c we have four values >=3 and <=4
>
> Note the last bar is special, because it contains all values
> less-than-or-equal-to the last interval.
>
> We do have a single meteogram example, and several bar chart examples, if
> you simply want to draw bars instead of XY plots.
>
> See:
>
> http://www.ncl.ucar.edu/Applications/bar.shtml
> http://www.ncl.ucar.edu/Applications/meteo.shtml
>
> --Mary
>
>
>
> On Tue, Nov 21, 2017 at 7:08 AM, Barry Lynn <barry.h.lynn at gmail.com>
> wrote:
>
>> Mary:
>>
>> Thank you for the suggestions yesterday. The histogram looks okay now.
>>
>> I'd like to bring to your attention a couple of things.
>>
>> 1) I believe that the examples you have on the site do not necessarily
>> (as is) plot histograms typically drawn in meteorological papers. For
>> instance, when I originally tried to just plot the data in mod_x and obs_x
>> using the standard examples it didn't work. For this reason, I created
>> intervals of data whose index is the interval value and the number of times
>> the index value appears is equal the value of the data (obs_x or obs_y)
>> within.
>>
>> For instance, if there is an interval with 10001 grids with dBZ values
>> (radar reflectivity) within this interval then that index will have 10001
>> values, all equal to the value of the index.
>>
>> 2) I do this with this loop and am wondering if there is an more concise
>> way to write it.
>>
>> i_num = 0
>>
>> i_end = 0
>>
>> i_beg = 0
>>
>> do i_int = 0,dims_obs_x-1
>>
>> i_end = i_beg + floattointeger(obs_x(i_int))
>>
>> do x_int = i_beg,i_end-1
>>
>> x_new(i_num) = i_int
>>
>> i_num = i_num + 1
>>
>> end do
>>
>> if (i_beg.eq.i_end)then
>>
>> x_new(i_num) = i_int
>>
>> i_num = i_num + 1
>>
>> end if
>>
>> i_beg = i_end
>>
>> end do
>>
>>
>> 3) If I take your program and substitute my data (num_x) at the top I get
>> the strange figure attached (00002.png). We're I to put this data into a
>> typical graphing program, the data would come out correctly as
>> histo_mod.pdf.
>>
>>
>> Perhaps I've overlooked something?
>>
>>
>> Thanks,
>>
>>
>> Barry
>>
>> On Mon, Nov 20, 2017 at 7:19 PM, Mary Haley <haley at ucar.edu> wrote:
>>
>>> Barry,
>>>
>>> You don't want to use discrete bin intervals, unless you are wanting to
>>> count the # of values *exactly equal* to a value.
>>>
>>> For a range of values, use gsnHistogramBinIntervals.
>>>
>>> Please read over the histogram page carefully, because we have many
>>> examples on this page that talk about the different histogram options.
>>>
>>> As I think I mentioned before, I updated example histo_2.ncl to show how
>>> to explicitly request an array of bin intervals.
>>>
>>> Run the attached script, will hopefully illustrate the difference
>>> between gsnHistogramBinIntervals and gsnHistogramDiscreteBinValues.
>>>
>>> --Mary
>>>
>>>
>>> On Mon, Nov 20, 2017 at 8:54 AM, Barry Lynn <barry.h.lynn at gmail.com>
>>> wrote:
>>>
>>>> Hello:
>>>>
>>>> I found the coding lines that allows me to map the number of intervals,
>>>> explicitly. I found the coding lines that allow me to specify how many of
>>>> the labels I want to map.
>>>>
>>>> That's here:
>>>>
>>>> https://www.ncl.ucar.edu/Applications/Scripts/histo_3.ncl
>>>>
>>>> res at tmXBLabelStride = 2 ; every other x-label
>>>> res at gsnHistogramDiscreteBinValues = ispan(0,25,1)
>>>>
>>>> However, I don't see how to change the number of labels to be different
>>>> from their default number, which equals the number of tmXBValues.
>>>>
>>>> I need to set the latter so that I can add more than 9 labels.
>>>>
>>>> Thank you
>>>>
>>>>
>>>> (0) res at tmXBLabels = -9
>>>>
>>>> (1) res at tmXBLabels = 0
>>>>
>>>> (2) res at tmXBLabels = 9
>>>>
>>>> (3) res at tmXBLabels = 18
>>>>
>>>> (4) res at tmXBLabels = 27
>>>>
>>>> (5) res at tmXBLabels = 36
>>>>
>>>> (6) res at tmXBLabels = 45
>>>>
>>>> (7) res at tmXBLabels = 54
>>>>
>>>> (8) res at tmXBLabels = 63
>>>>
>>>> (0) tmXBValues = 0.0555556
>>>>
>>>> (1) tmXBValues = 0.166667
>>>>
>>>> (2) tmXBValues = 0.277778
>>>>
>>>> (3) tmXBValues = 0.388889
>>>>
>>>> (4) tmXBValues = 0.5
>>>>
>>>> (5) tmXBValues = 0.611111
>>>>
>>>> (6) tmXBValues = 0.722222
>>>>
>>>> (7) tmXBValues = 0.833333
>>>>
>>>> (8) tmXBValues = 0.944444
>>>>
>>>> On Mon, Nov 20, 2017 at 3:01 PM, Barry Lynn <barry.h.lynn at gmail.com>
>>>> wrote:
>>>>
>>>>> Hi:
>>>>>
>>>>> I can get the labels to display correctly if I use:
>>>>>
>>>>> res at tmXBLabels = int_radar(::3)
>>>>>
>>>>>
>>>>> However, the histogram program is amalgamating the smaller bins into
>>>>> 10 sized default bins.
>>>>>
>>>>>
>>>>> I would hope that there is a way to explicitly tell the histogram
>>>>> program to use all the interval data (23 intervals.
>>>>>
>>>>>
>>>>> I tried setting:
>>>>>
>>>>>
>>>>> res at tmXBMode = "Manual"
>>>>>
>>>>> and creating manual tick marks, but then my histogram labels go only
>>>>> from 0 to 1.
>>>>>
>>>>>
>>>>> As below.
>>>>>
>>>>>
>>>>> rad_inc = 3./(int_radar(dimsizes(int_radar)-1)+10)
>>>>>
>>>>> print("rad_inc = " +rad_inc)
>>>>>
>>>>> new_ticks = new(dimsizes(int_radar),float)
>>>>>
>>>>> new_ticks(0)= 0
>>>>>
>>>>> do inc = 1,dimsizes(int_radar)-1,1
>>>>>
>>>>> new_ticks(inc) = new_ticks(inc-1)+rad_inc
>>>>>
>>>>> end do
>>>>>
>>>>> print("new_ticks = " + new_ticks)
>>>>>
>>>>> res at tmXBValues := new_ticks
>>>>>
>>>>> res at tmXBLabels := int_radar
>>>>>
>>>>> On Sun, Nov 19, 2017 at 9:21 PM, Barry Lynn <barry.h.lynn at gmail.com>
>>>>> wrote:
>>>>>
>>>>>> Hi:
>>>>>>
>>>>>> I am having trouble figuring out why my histo.ncl program won't plot
>>>>>> data beyond value (x-axis) of 15. This is really dbz data, so the range is
>>>>>> correct: -9 to 60.
>>>>>>
>>>>>> I also checked that the labels are present in:
>>>>>>
>>>>>> res at tmXBLabels = int_radar
>>>>>>
>>>>>>
>>>>>> and the data dimensions are correct (23 elements).
>>>>>>
>>>>>> However, I don't see any data (and any labels 18-60) indicating that
>>>>>> the data has all been displayed.
>>>>>>
>>>>>> Thank you,
>>>>>>
>>>>>> Barry
>>>>>>
>>>>>> --
>>>>>> 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>
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20171121/5e9c2287/attachment-0001.html>
More information about the ncl-talk
mailing list