[ncl-talk] Plot barchart in each grid box of a gridded file

Dennis Shea shea at ucar.edu
Mon Nov 11 08:27:41 MST 2019


There is no explicit function to do that. This has to be a custom plot.
===
*http://www.ncl.ucar.edu/Applications/histo.shtml*
<http://www.ncl.ucar.edu/Applications/histo.shtml>
example 9
===
Perhaps, other have done this and have better ideas.
An overview of the process follows. It is your job to manage the plot.

[1] Decide the number of histograms you want to plot. Your example was 3x5
+ 3x4=>27. I will use 6x5 for convenience]
[2] Based upon [1] specify a histogram size
[3] Draw background map  [gsnFrame=False; *gsn_csm_map*
<http://www.ncl.ucar.edu/Document/Graphics/Interfaces/gsn_csm_map.shtml>]
[4] It looks like blocks [windows] of grid points were used to create the
distribution
Loop over grid block locations.
     NY = 6
     MX = 5
     plot_hist = new (/NY,MX/), "graphic")
     ixblock =                ; block size in 'x' [longitude direction]
     jyblock =                ;                      'y' [latitude
direction]
     nplt      = -1
     do nblock=1,NBLOCK
          xloc =                    ; location of 1st histogram
          yloc =

         do jy=jyStrt,jyLast
            do ix=ixStrt,ixLast
                    ....
            end do                            ; ix
          end do                              ; jy

;   plot current histogram at centroid of grid location block
          ixCenter = (ixStrt+ixLast)/2
          jyCenter = (jyStrt+jyLast)/2

          nplt = nplt + 1
          plot(nplt)_ = gsn_histogram(...)

          ixStrt  = ixStrt+ixBlock     ; update indices for next block
          ixLast = ixLast+ixBlock
          jyStrt  = ixStrt+jyBlock
          jyLast = jyLast+jyBlock

          xloc = xloc + ...
          yloc = yloc + ..

      end do                                  ; nblock
      frame(wks)

====
Rather than 'do' loops,
         do jy=jyStrt,jyLast
            do ix=ixStrt,ixLast
                    ....
            end do                            ; ix
          end do                              ; jy

These internal loops do loops, you could likely use functions with syntax
like

      Q([..,..,jyStrt:jyLast,ixStrt:ixLast)   ; data block


On Sun, Nov 10, 2019 at 9:02 AM Lyndz via ncl-talk <ncl-talk at ucar.edu>
wrote:

> Dear NCL expert,
>
> I would like to plot a similar plot as in the attached file:
> Barchart of rainfall in each gridbox.
>
>
> I did this manually by extracting the values in each grid point within the
> domain,
> plotting the barcharts individually (almost transparent) and manually
> overlaying them on the map.
>
> I used CMAP for this with a 2.5 x 2.5 degree grid resolution.
>
> I would like to ask for suggestions on how I can do this in a script using
> NCL.
> I know how to plot a barchart, but how do you do this per grid point and
> plot at the center of each gridpoint?
>
> I'll appreciate any help you can provide.
>
> *Lyndz*
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> 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/20191111/b6a0ce7e/attachment.html>


More information about the ncl-talk mailing list