[ncl-talk] boxplot with flipped axes

Alan Brammer abrammer at albany.edu
Fri Mar 13 15:56:56 MDT 2015


My bad, in my haste I forgot which way was up.

Below is the sister function which is the orientation you actually wanted.
 plus brief description of the arguments, hopefully it's obvious. Will only
do 1 box at a time currently.

If you want min/max instead of 10% 90% for the ends just change frac_limits
accordingly 0./1.


wks:  workstation associated with plot
plot:  the plot to draw the boxes over
xIn[*] : numeric, array of data to be used to calculate the boxes from
yIn: single numeric in the y to center boxes on.
res : resources to impact the gsn_add_polyline routines.



> undef("add_boxplot_horizontal")procedure add_boxplot_horizontal(wks, plot, xIn, yIn, res)local xIn, yIn, res, x, nx, frac_limits, ind_limits, limits, box_widthbegin
>
> if(res.eq.True .and. isatt(res, "box_width"))
> box_width = res at box_width
> else
> box_width = 1.
> end if
>
> x = xInqsort(x)nx = dimsizes(xIn)frac_limits =  (/0.1, 0.25,0.5, 0.75, 0.9/)ind_limits = toint( (frac_limits * nx) - 1) > 0limits =  x(ind_limits)plot@$unique_string("line")$ = gsn_add_polyline(wks, plot, (/limits(0), limits(1)/), (/yIn, yIn/), res)plot@$unique_string("line")$ = gsn_add_polyline(wks, plot, (/limits(3), limits(4)/), (/yIn, yIn/), res)plot@$unique_string("line")$ = gsn_add_polyline(wks, plot, (/limits(2), limits(2)/), (/yIn-box_width, yIn+box_width/), res)plot@$unique_string("line")$ = gsn_add_polyline(wks, plot, (/limits(1), limits(1),limits(3), limits(3), limits(1)/), (/yIn-box_width, yIn+box_width, yIn+box_width,yIn-box_width,yIn-box_width /), res)if(res.eq.True .and. isatt(res,"whisker_end") .and. res at whisker_end.eq.True)  plot@$unique_string("line")$ = gsn_add_polyline(wks, plot, (/limits(0), limits(0)/), (/yIn-box_width, yIn+box_width/), res)  plot@$unique_string("line")$ = gsn_add_polyline(wks, plot, (/limits(4), limits(4)/), (/yIn-box_width, yIn+box_width/), res)end ifreturnend
>
>
>

On Fri, Mar 13, 2015 at 5:47 PM, Alan Brammer <abrammer at albany.edu> wrote:

> This is a little different to the version boxplot function Dennis put
> together but I wanted to do the same a while back so made this procedure.
> Rather than drawing it's own plot the function will add a box to an
> existing plot.  So in the example you sent, you'd have the xy line plot and
> then you'd have to loop over this a lot of times, but it would get the job
> done.
>
> As you can probably see everything is polylines so res takes standard
> gsLine* resources the two extra resources I had, were box_width to
> determine in plot units how wide the box should be.  Also whisker_end as a
> logical to choose whether your want a line at the end or just leave it.
>
> Let me know if you have issues with this if you do loop many times.  I've
> found elsewhere that unique_string() starts to slow down significantly if
> called hundreds+ times.
>
> Alan.
>
> undef("add_boxplot_vertical")
>> procedure add_boxplot_vertical(wks, plot, xIn, yIn, res)
>> local xIn, yIn, res, x, nx, frac_limits, ind_limits, limits, box_width
>> beginif(res.eq.True .and. isatt(res, "box_width"))
>> box_width = res at box_width
>> else
>> box_width = 1.
>> end ify = yIn
>> qsort(y)
>> ny = num(.not.ismissing(y));    dimsizes(yIn)  only account non missing data.
>>
>> frac_limits =  (/0.1, 0.25,0.5, 0.75, 0.9/)   ; percentiles for whisker , box, mid line, box, whisker.
>> ind_limits = toint( (frac_limits * ny) - 1) > 0limits =  y(ind_limits)
>>
>> plot@$unique_string("line")$ = gsn_add_polyline(wks, plot,(/xIn, xIn/), (/limits(0), limits(1)/), res)
>> plot@$unique_string("line")$ = gsn_add_polyline(wks, plot,(/xIn, xIn/), (/limits(3), limits(4)/),  res)
>> plot@$unique_string("line")$ = gsn_add_polyline(wks, plot,  (/xIn-box_width, xIn+box_width/), (/limits(2), limits(2)/), res)
>> plot@$unique_string("line")$ = gsn_add_polyline(wks, plot,  (/xIn-box_width, xIn+box_width, xIn+box_width,xIn-box_width,xIn-box_width /), (/limits(1), limits(1),limits(3), limits(3), limits(1)/), res)if(res.eq.True .and. isatt(res,"whisker_end") .and. res at whisker_end.eq.True)
>>   plot@$unique_string("line")$ = gsn_add_polyline(wks, plot, (/xIn-box_width, xIn+box_width/), (/limits(0), limits(0)/), res)
>>   plot@$unique_string("line")$ = gsn_add_polyline(wks, plot, (/xIn-box_width, xIn+box_width/), (/limits(4), limits(4)/), res)
>> end ifreturn
>> end
>
>
>
> On Fri, Mar 13, 2015 at 5:27 PM, Michael Mills <mmills at ucar.edu> wrote:
>
>> I would like to create a plot similar to that attached. I have
>> investigated the boxplot routine, and it seems to only work for vertical
>> boxes, plotted against the horizontal axis. Has anyone developed a routine
>> to do the same for horizontal boxes plotted against the vertical axis?
>>
>> Mike Mills
>> NCAR
>>
>> _______________________________________________
>> ncl-talk mailing list
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20150313/5ff3d34c/attachment-0001.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screen Shot 2015-03-13 at 15.01.06 .png
Type: image/png
Size: 116442 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20150313/5ff3d34c/attachment-0001.png 


More information about the ncl-talk mailing list