[ncl-talk] Issue with creating a bar chart plot

Dave Allured - NOAA Affiliate dave.allured at noaa.gov
Mon Jun 8 11:39:54 MDT 2020


Andrew,

In the face of unknown behavior, I would try a couple things.  First, go
back to your original code without my previous suggestion of reversing the
axes.  That was based on a wrong assumption.

1.  I do not understand the purpose of "tolong" here.  Data type "long" is
normally used only for special purposes in NCL, and there is a chance it is
causing trouble.  Also, "tolong" would reduce plot accuracy by integer
truncation.  Try simply removing "tolong", and use temperature_top(i,0:23)
directly in the function call.  Tofloat, todouble, or toint would be safer
alternatives if a conversion function is really needed.  If you really want
integer rounding here, then you should use the round function to reduce
roundoff error.

2.  Try completely isolating the plot function from the rest of the
program.  Write the X and Y arrays to a small Netcdf file.  Print (res) and
manually recode the printed results into new NCL code lines in a small new
test program.  Omit all "res" attributes that are not relevant for this
plot type.  Read the Netcdf file, then call open_wks and gsn_csm_xy, and
see if the problem remains.  This way, at least you end up with a small
reproducer and small data that you can send to the mailing list.  HTH.


On Mon, Jun 8, 2020 at 7:17 AM Rick Brownrigg <brownrig at ucar.edu> wrote:

> I took a quick look at the code. As the errors indicate, it's happening in
> a function call get_bart_width(). The calculation of the variable "delta"
> is clearly wrong, and that sets off the warning, and triggers the error
> later in get_bar_arrays about non-monotonicity (it's actually not that the
> array is non-monotonic, it's that it has negative widths).
>
> Beyond that, I can not tell why the calculation is wrong, particularly
> without the data. That part of the code hasn't changed in some years, so
> the v6.5.0 vs v6.6.2 difference is a mystery.
>
> FWIW...
> Rick
>
>
> On Sun, Jun 7, 2020 at 6:58 PM Andrew Kren - NOAA Affiliate via ncl-talk <
> ncl-talk at mailman.ucar.edu> wrote:
>
>> I looked into these things. My x_axis is simply created this way:
>>
>> x_axis = ispan(4,73,3)
>>
>>
>> And the printed values are correct, increasing by 3 starting at 4, 7, etc.
>>
>>
>> So this is still kinda confusing as to why.
>>
>> On Sun, Jun 7, 2020 at 5:41 PM Dave Allured - NOAA Affiliate <
>> dave.allured at noaa.gov> wrote:
>>
>>> It is only the horizontal axis that needs to be monotonically
>>> increasing.  That is probably what the error message is about.  Naturally,
>>> the vertical access may fluctuate anywhere.  You might want to check the
>>> values of x_axis in your code to see if they make sense.
>>>
>>> Meanwhile, you should be able to insert a quick fix for x_axis with
>>> temporary arrays, something like this.  This assumes that x_axis is
>>> strictly decreasing rather than increasing.  If you change the order, then
>>> you must also change the order for the vertical axis data, in the same
>>> way.  X and Y values are supposed to form ordered pairs to make the bar
>>> chart.
>>>
>>> xplot = x_axis(::-1)
>>> yplot = tolong (temperature_top(i,23:0:-1))
>>> plot = gsn_csm_xy (wks, xplot, yplot, res)
>>>
>>> I have no idea what changed to cause a newer NCL version to change from
>>> the original behavior.
>>>
>>>
>>> On Sun, Jun 7, 2020 at 1:57 PM Andrew Kren - NOAA Affiliate via ncl-talk
>>> <ncl-talk at mailman.ucar.edu> wrote:
>>>
>>>> Dear ncl-talk,
>>>>
>>>> I upgraded my NCL to the latest version. Previously I was using version
>>>> 6.5. When I upgraded, one of my ncl codes no longer runs successfully but
>>>> creates an error code. I am creating a bar chart with gsn_csm_xy. I
>>>> originally did not get these errors so I am unsure what could be going on.
>>>> I tried to debug the issue but to no avail. Here are my errors:
>>>>
>>>> (0) get_bar_widths: Warning: The bar width(s) you selected (0.75) is
>>>> larger than the smallest delta (-11).
>>>>
>>>> (0) Defaulting to -11.
>>>>
>>>> (0) get_bar_arrays: Fatal: The array is not monotonically increasing.
>>>>
>>>> (0) Cannot draw a bar chart.
>>>>
>>>> fatal:Illegal right-hand side type for assignment
>>>>
>>>>
>>>> I checked that my array I am plotting has all correct values, and it
>>>> does. I didn't know a bar chart had to have monotonically increasing
>>>> values. Is there a way around this?
>>>>
>>>>
>>>> The code where it fails is below, in the call to plot.
>>>>
>>>>
>>>> plot = gsn_csm_xy(wks,x_axis,tolong(temperature_top(i,0:23)),res)
>>>>
>>>> Thanks,
>>>>
>>>> --
>>>> Andrew Kren
>>>> Meteorologist
>>>> US Dept of Commerce
>>>> National Oceanic and Atmospheric Administration
>>>> National Weather Service Raleigh, NC
>>>> 1005 Capability Drive, Suite 300
>>>> Centennial Campus
>>>> Raleigh, NC 27606-5226
>>>>
>>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20200608/cce272b0/attachment.html>


More information about the ncl-talk mailing list