Re: Replace Frequency With Percent in Histogram

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Thu Mar 18 2010 - 15:01:53 MDT

I hope I have some more "simple" fixes to gsn_code.ncl to get what
you want.

First, we can have this settable via a resource, so that you don't
have to go into gsn_code.ncl everytime and edit this.

Edit gsn_code and search for the line:

     xnpts = npts*1.

"xnpts" is the total number of points you have for that particular
data set (npts is an integer).

This is the thing you'll want to set to whatever maximum number of
points you'll have. You will need to
know this apriori in order to get the calculations correct for all
the histograms.

Change the above line to this:

     xnpts = get_res_value(res2,"gsnHistogramNptsForPercent",npts) * 1.

This effectively sets xnpts=npts*1., unless you set the resource:

    res@gsnHistogramNptsForPercent

to whatever value you want. You can call this resource whatever you
want.

Furthermore, change these two lines:

     bins_at_pnice = 0.01 * (npts * pnice)
     bins_at_pmnice = 0.01 * (npts * pmnice)

to use "xnpts" instead of "npts":

     bins_at_pnice = 0.01 * (xnpts * pnice)
     bins_at_pmnice = 0.01 * (xnpts * pmnice)

I think this should do it.

Additionally, in your main program, you might want to set
res@trYMaxF to the same value for all histograms, if you want
to keep them the same scale.

--Mary

On Mar 18, 2010, at 2:25 PM, Mary Haley wrote:

> Dan,
>
> In answer to your second question, I was hoping it's as easy as
> setting trYMaxF to the maximum value you plan to have, but I'm not
> so sure. Let me see if I can create an example.
>
> --Mary
>
> On Mar 18, 2010, at 8:03 AM, Dan Barrie wrote:
>
>> That worked perfectly, and having edited gsn_code.ncl for the
>> first time, I'd like to thank you for how well-written and
>> commented the code is.
>>
>> For anyone else who reads this thread in the future, I found it
>> necessary to change two more things:
>>
>> 1. Get rid of the "Percent" label on the right Y-axis. This is
>> accomplished by altering line 7764 of the code (gsn_code.ncl). I
>> changed the line perc_String = "Percent" to perc_String = ""
>> 2. To get rid of the tick marks on the right Y-axis, I added the
>> following resource to my histogram script: res@tmYROn = False
>>
>> Mary, I have one more question about this histogram. The only
>> remaining issue is that the left y-axis is being scaled to
>> frequency values, not percentage values, which is a problem, since
>> my data sets have different numbers of data points, and I am
>> automating their handling as much as possible. For example, 40% in
>> one data set might be 8000 points, but 40% in another data set
>> might be 1000 points. I would like to keep the scaling constant,
>> so is there a way to switch the scaling so that the left y-axis
>> can be scaled by percentage? Thanks!
>>
>> -Dan
>>
>>
>>
>>
>> Mary Haley wrote:
>>>
>>> Hi Dan,
>>>
>>> The histogram code only allows you to put these special labels on
>>> the right.
>>>
>>> If you want to put them on the left, you will need to make a
>>> personal
>>> copy of $NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl and
>>> edit it.
>>>
>>> Where you see the lines:
>>>
>>> set_attr(res2,"tmYUseLeft", False)
>>> set_attr(res2,"tmYROn",True)
>>> set_attr(res2,"tmYRLabelsOn",True)
>>> set_attr(res2,"tmYRMode","Explicit")
>>> set_attr(res2,"tmYRValues",bins_at_pnice)
>>> set_attr(res2,"tmYRMinorValues",bins_at_pmnice)
>>> if(percentsign)
>>> set_attr(res2,"tmYRLabels",pnice+"%")
>>> else
>>> set_attr(res2,"tmYRLabels",pnice)
>>> end if
>>>
>>>
>>> You will want to change YR to YL.
>>>
>>> I haven't actually tested this, so let me know if it doesn't work.
>>>
>>> You will also need to do Dennis' suggestion below of setting
>>> tiYAxisString to "Percent" or "%".
>>>
>>> --Mary
>>>
>>>
>>> On Mar 17, 2010, at 9:28 AM, Dennis Shea wrote:
>>>
>>>> Try
>>>>
>>>> res@tiYAxisString = "Percent"
>>>>
>>>> On 03/17/2010 08:36 AM, Dan Barrie wrote:
>>>>> Dear NCL users,
>>>>>
>>>>> I would like to replace the default histogram left Y-Axis
>>>>> values for
>>>>> "Frequency" with "Percent", which appears on the right Y-Axis
>>>>> by default
>>>>> when res@gsnHistogramComputePercentages is set to True. Does
>>>>> anyone have
>>>>> a suggestion for how to do this? Thanks.
>>>>>
>>>>> -Dan
>>>>> _______________________________________________
>>>>> ncl-talk mailing list
>>>>> List instructions, subscriber options, unsubscribe:
>>>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>>
>>>>
>>>> --
>>>> ======================================================
>>>> Dennis J. Shea tel: 303-497-1361 |
>>>> P.O. Box 3000 fax: 303-497-1333 |
>>>> Climate Analysis Section |
>>>> Climate & Global Dynamics Div. |
>>>> National Center for Atmospheric Research |
>>>> Boulder, CO 80307 |
>>>> USA email: shea 'at' ucar.edu |
>>>> ======================================================
>>>> _______________________________________________
>>>> ncl-talk mailing list
>>>> List instructions, subscriber options, unsubscribe:
>>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>
>> _______________________________________________
>> ncl-talk mailing list
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Thu Mar 18 15:02:56 2010

This archive was generated by hypermail 2.1.8 : Fri Mar 19 2010 - 16:19:08 MDT