[ncl-talk] Issue with creating a bar chart plot
Andrew Kren - NOAA Affiliate
andrew.kren at noaa.gov
Mon Jun 8 18:31:02 MDT 2020
Hi ncl-talk, Dave, and Rick,
I took both of your guys' advice and here is what I found. I first removed
tolong but that did not fix it. I then tried dong rounding, as well as not
doing any conversion, but that still resulted in the error. Then I tried
commenting out the defining of the bar chart width, but it still came up
with the same error:
(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
Here is what I have for my plot section:
outfile = "fcst_efuuyr3wd6_top_1_" + (i)
length1 = temperature_top(i,0:23)
wks = gsn_open_wks("eps",outfile) ; send graphics to PNG file
res = True
res at gsnScale = True
res at gsnFrame = False
res at gsnDraw = True
; these four resources allow the user to stretch the plot size, and
; decide exactly where on the page to draw it.
;res at gsnMaximize = True
res at vpXF = 0.01 ; In page coordinates, where to start
res at vpYF = 0.9 ; 0.75 ; the plot
res at vpHeightF = 0.27 ; Changes the aspect ratio
res at vpWidthF = 0.97
x_axis = ispan(4,73,3)
x_axis at _FillValue = 999
res at tiMainString = names_14ers(i) + " 3-Day Forecast (Peak: " +
hgts_14ers_str(i) + " ft)"
res at gsnXYBarChart = True ; Create bar plot
res at tiMainOffsetYF = 0.006
res at tiMainFontHeightF = 0.02
res at tmXTMode = "Explicit" ; Define own tick mark labels.
res at tmXTValues = x_axis
res at tmXTOn = False ; turn on the top tickmarks
res at tmXBOn = False
res at tmYROn = False
res at tmYRMinorOn = False
res at tmYLOn = False
res at tmYLMinorOn = False
res at tmXTMinorOn = False
res at gsnXRefLine = (/26.5,50.5/)
res at gsnXRefLineColor = (/"gray40","gray40"/)
res at gsnXRefLineDashPatterns = (/2,2/)
res at gsnXRefLineThicknesses = (/1.05,1.05/)
res at tiYAxisOffsetXF = 0.035
res at tiYAxisString = "Temperature"
res at tiYAxisFontHeightF = 0.014
range_temp = ( tofloat( max(tolong(temperature_top(i,0:23))) -
min(tolong(temperature_top(i,0:23)))))
max_temp = tofloat(max(tolong(temperature_top(i,0:23)))) +
(tofloat(max(tolong(temperature_top(i,0:23))) -
min(tolong(temperature_top(i,0:23))))) * 0.8
min_temp = tofloat(min(tolong(temperature_top(i,0:23)))) -
(tofloat(max(tolong(temperature_top(i,0:23))) -
min(tolong(temperature_top(i,0:23))))) * 0.1
res at trYMaxF = max_temp ; max value on y-axis
res at trYMinF = min_temp
; res at gsnXYBarChartBarWidth = 0.75 ; change bar widths 0.75
originally
res at gsnXYBarChartColors = "Orange"
; draw 5 separate temperature plots so can make figure big
res at trXMinF = 0 ; adds space on either end
res at trXMaxF = 75 ; of the 1st and last
bars
plot = gsn_csm_xy(wks,x_axis,temperature_top(i,0:23),res)
My x_axis values are: 4 to 73 by 3
My temperature_top values are:
(0) 14
(1) 11
(2) 11
(3) 12
(4) 14
(5) 21
(6) 24
(7) 23
(8) 23
(9) 22
(10) 23
(11) 26
(12) 33
(13) 36
(14) 33
(15) 28
(16) 25
(17) 25
(18) 25
(19) 29
(20) 38
(21) 41
(22) 39
(23) 35
I don't understand why the error could still be happening.
Thanks,
On Mon, Jun 8, 2020 at 1:40 PM Dave Allured - NOAA Affiliate <
dave.allured at noaa.gov> wrote:
> 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
>>>>>
>>>>
--
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/3e295e54/attachment.html>
More information about the ncl-talk
mailing list