[ncl-talk] boxplot with flipped axes
Alan Brammer
abrammer at albany.edu
Fri Mar 13 15:47:08 MDT 2015
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/7a15f42e/attachment.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/7a15f42e/attachment.png
More information about the ncl-talk
mailing list