[ncl-talk] Hatch over contour plot

Mary Haley haley at ucar.edu
Thu Mar 8 16:13:40 MST 2018


Hi Marston,

Thanks for the clarification, I understand now!

I don't think you are barking up the wrong tree, but the tree may have some
errors.  :-)

In order to draw a polygon, you need to provide a closed loop.  Maybe try:

  ypt =(/-50.0,-50.0,-27.5,-27.5,-50.0/)
  xpt =(/0.0,19.0,19.0,0.0,0.0/)
  polyres             = True
  polyres at gsFillColor = "black"
  polyres at gsFillIndex = 3
  polyres at gsFillOpacityF = 0.2
  dum2 = gsn_add_polygon(wks,plot(0),xpt,ypt,polyres) ; add polygon

Since I already had an example of doing an overlay where the different
curves have different axes limits, I took that and added your hatching
code. But, I commented out the gsFillIndex and made it just a fill color
instead.  See the attached.

Were you trying to do both fill *and* hatching? If so, I think you have to
do them separately, because you can't specify both a fill color and a hatch
pattern for a single polygon call:

  ypt =(/-50.0,-50.0,-27.5,-27.5,-50.0/)
  xpt =(/0.0,19.0,19.0,0.0,0.0/)
  polyres             = True
  polyres at gsFillColor = "black"
  polyres at gsFillOpacityF = 0.2
  dum2_fill = gsn_add_polygon(wks,plot(0),xpt,ypt,polyres) ; add polygon

  polyres at gsFillIndex = 3
  dum2_hatch = gsn_add_polygon(wks,plot(0),xpt,ypt,polyres) ; add polygon

--Mary



On Thu, Mar 8, 2018 at 1:37 PM, Marston Ward <marston.johnston at gu.se> wrote:

> Hi Jared & Mary,
>
> Thanks for the responses. These are all good and show, for me, new ways to
> use NCL.
> Unfortunately, as Jared pointed out, I’m not trying to hatch my figure
> based on the contours values.
> I’m working on a publication so forgive me if I hesitate to send to all of
> ncl-talk. Let me explain a bit more.
>
> I have to two panel containing 2 plots, but these plots have x-axis of
> different lengths (just by 1 value) e.g., plot 1 has a x-value from 0:10
> and plot 2: 1:10.
> Since I’m comparing model results with observations I would like to put a
> hatch box over the plot 1 between x= 0 and x= 1 so that the reader can
> still see the contours beneath but note the different ranges of the plots.
>
> The examples Mary suggested didn’t really cover this example. apologies
> for not being more clear first time around.
>
> I tried the following with the thought of adding a box with hatch fill
> between x= 0 and x=1 but zero effect later when I plot the panel.
>
>   ypt =(/-50.0,-27.5/)
>   xpt =(/0.0,19.0/)
>   polyres             = True
>   polyres at gsFillColor = "black"
>   polyres at gsFillIndex = 3
>   polyres at gsFillOpacityF = 0.2
>   dum2 = gsn_add_polygon(wks,plot(0),xpt,ypt,polyres) ; add polygon
>
> Am I barking up the wrong tree here or am I making an error somewhere?
>
> Appreciate the help guys,
> /M
>
>
> On 8 Mar 2018, at 18:30, Mary Haley <haley at ucar.edu> wrote:
>
> Hi Marston,
>
> If you simply want to draw hatching on top of an existing contour plot,
> then you can use gsn_contour_shade.
>
> http://www.ncl.ucar.edu/Document/Graphics/Interfaces/
> gsn_contour_shade.shtml
>
> This function is for the sole purpose of taking an existing contour plot,
> and adding some hatching or stippling to highlight an area of interest.
>
> Here are some examples:
>
> http://www.ncl.ucar.edu/Applications/conOncon.shtml#ex4
> http://www.ncl.ucar.edu/Applications/coneff.shtml#ex11
> http://www.ncl.ucar.edu/Applications/overlay.shtml#ex5
> http://www.ncl.ucar.edu/Applications/wavelet.shtml#ex3
>
> Some of these may not use gsn_contour_shade.
>
> Let ncl-talk know if this is not what you're after.
>
> --Mary
>
>
> On Thu, Mar 8, 2018 at 3:47 AM, Marston Ward <marston.johnston at gu.se>
> wrote:
>
>> Hi,
>>
>> I’m trying to mask a part of a  gsn_csm_contour plot using a “hatch”. I
>> don’t want to simply mask out the area because I want to the data to still
>> be visible under the hatch.
>> Is it possible to do this in NCL? A simple search returned nothing in
>> NCL. Just wondering if this is possible and it so, are there examples.
>>
>> Best,
>>
>> /M
>>
>> *Marston S. Ward*
>>
>> _______________________________________________
>> ncl-talk mailing list
>> ncl-talk at ucar.edu
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
>>
> _______________________________________________
> 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/20180308/7b64dd14/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: overlay.png
Type: image/png
Size: 112673 bytes
Desc: not available
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20180308/7b64dd14/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: overlay_with_fill.ncl
Type: application/octet-stream
Size: 3251 bytes
Desc: not available
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20180308/7b64dd14/attachment.obj>


More information about the ncl-talk mailing list