<div style="font-family: tahoma , arial , helvetica , sans-serif;font-size: 12.0px;">
 Hi Dave,
</div>
<div style="font-family: tahoma , arial , helvetica , sans-serif;font-size: 12.0px;">
 <br>
</div>
<div style="font-family: tahoma , arial , helvetica , sans-serif;font-size: 12.0px;">
 Thanks for the hint. I haven't thought about looping gsn_add_polygon over years, and setting five (!) vertices. I've managed to find a good setting (see code snippet below and attached plot). 
</div>
<div style="font-family: tahoma , arial , helvetica , sans-serif;font-size: 12.0px;">
 <br>
</div>
<div>
 <font face="tahoma, arial, helvetica, sans-serif"><span style="font-size: 12.0px;">do j = 0, nyear-1</span></font>
</div>
<div>
 <font face="tahoma, arial, helvetica, sans-serif"><span style="font-size: 12.0px;">if (.not.ismissing(temp_amip2_tpi_year_filter(j))) then</span></font>
</div>
<div>
 <font face="tahoma, arial, helvetica, sans-serif"><span style="font-size: 12.0px;">if (temp_amip2_tpi_year_filter(j).lt.0.) then</span></font>
</div>
<div>
 <font face="tahoma, arial, helvetica, sans-serif"><span style="font-size: 12.0px;"> plot1x(j) = gsn_add_polygon(wks,plot1g(i),(/years(j)-0.5,years(j)+0.5,years(j)+0.5,years(j)-0.5,years(j)-0.5/),(/temp_amip2_tpi_year_filter(j)-1.e2,temp_amip2_tpi_year_filter(j)-1.e2,temp_amip2_tpi_year_filter(j)+1.e2,temp_amip2_tpi_year_filter(j)+1.e2,temp_amip2_tpi_year_filter(j)-1.e2/),pg_res)</span></font>
</div>
<div>
 <font face="tahoma, arial, helvetica, sans-serif"><span style="font-size: 12.0px;">end if</span></font>
</div>
<div>
 <font face="tahoma, arial, helvetica, sans-serif"><span style="font-size: 12.0px;">end if</span></font>
</div>
<div>
 <font face="tahoma, arial, helvetica, sans-serif"><span style="font-size: 12.0px;">end do</span></font>
</div>
<div style="font-family: tahoma , arial , helvetica , sans-serif;font-size: 12.0px;">
 <br>
</div>
Cheers,<div>Giorgio<br>
<blockquote style="font-family: tahoma , arial , helvetica , sans-serif;font-size: 12.0px;">
  ----Messaggio originale---- 
 <br> Da: dave.allured@noaa.gov 
 <br> Data: 10-mar-2021 14.04 
 <br> A: "Giorgio Graffino"<g.graffino@tim.it> 
 <br> Cc: <ncl-talk@ucar.edu> 
 <br> Ogg: Re: [ncl-talk] Drawing several polygons on a xy plot 
 <br>
 <br>
 <div dir="ltr">
  <div>
    P.S.  I just remembered you are making a panel plot.  You will probably need to increase the size of the graphics array to hold all polygons in all six panels, due to that memory requirement.  Something like this: 
  </div>
  <div>
   <br>
  </div>
  <div>
        poly = new ( (/ nyears, npanels /), graphic) 
   <br>
  </div>
  <div>
   <br>
  </div>
  <div>
    There is more than one way to do this.  The array can be 1-D, 2-D, or 3-D, whatever you think is most convenient for the looping and indexing structure of your program. 
  </div>
  <div dir="ltr">
   <br>
  </div>
  <br>
  <div class="gmail_quote">
   <div dir="ltr" class="gmail_attr">
     On Wed, Mar 10, 2021 at 5:54 AM Dave Allured - NOAA Affiliate < 
    <a href="javascript:handleMailto('mailto:_javascript:handlemailto( mailto:dave.allured@noaa.gov );return false;');return false;">dave.allured@noaa.gov</a>> wrote: 
    <br>
   </div>
   <blockquote class="gmail_quote" style="margin: 0.0px 0.0px 0.0px 0.8ex;border-left-width: 1.0px;border-left-style: solid;border-left-color: rgb(204,204,204);padding-left: 1.0ex;">
    <div dir="ltr">
     <div dir="ltr">
      <div>
        Gsn_add_polygon does not work like that.  It draws only a single polygon per call, and you must specify all vertices of the polygon.  Missing values can not be used to create discontinuities or unfilled areas of a polygon. 
      </div>
      <div>
       <br>
      </div>
      <div>
        The simplest approach is to draw multiple polygons, one narrow rectangle for each year on the X axis.  Loop over years, and skip (i.e. do not draw) polygons unless the IPO index is negative.  Within the loop, remember to assign each polygon to a different element of a type graphics array, to satisfy the memory requirement of the function. 
      </div>
      <div>
       <br>
      </div>
      <div>
            poly = new (nyear, graphic) 
      </div>
      <div>
            do i = 0, nyear-1 
       <br>        if (temp_amip2_tpi_year_filter(i) .lt. 0) then 
       <br>            poly(i) = gsn_add_polygon (...) 
      </div>
      <div>
                end if 
      </div>
      <div>
            end do 
      </div>
      <div>
       <br>
      </div>
      <div>
        I leave it up to you to calculate the correct polygon vertices for each year.  Your initial code version is almost doing this already.  I recommend using a fully closed polygon for each year.  That is 5 vertices, not 4, for each rectangle.  Function behavior for non-closed polygons is undefined. 
      </div>
      <div>
       <br>
      </div>
      <br>
      <div class="gmail_quote">
       <div dir="ltr" class="gmail_attr">
         On Wed, Mar 10, 2021 at 3:20 AM Giorgio Graffino via ncl-talk < 
        <a href="javascript:handleMailto('mailto:_javascript:handlemailto( mailto:ncl-talk@mailman.ucar.edu );return false;');return false;">ncl-talk@mailman.ucar.edu</a>> wrote: 
        <br>
       </div>
       <blockquote class="gmail_quote" style="margin: 0.0px 0.0px 0.0px 0.8ex;border-left-width: 1.0px;border-left-style: solid;border-left-color: rgb(204,204,204);padding-left: 1.0ex;">
        <font face="tahoma, arial, helvetica, sans-serif">Short addition to this thread: I'm running NCL 6.6.2 on </font>
        <span style="font-family: monospace;"><span style="background-color: rgb(255,255,255);">Linux 5.4.101-1-MANJARO.</span></span>
        <div>
         <br>
        </div>
        <div>
          Best, 
        </div>
        <div>
          Giorgio 
        </div>
        <div>
         <blockquote style="font-family: tahoma , arial , helvetica , sans-serif;">
           ----Messaggio originale---- 
          <br> Da: 
          <a href="javascript:handleMailto('mailto:_javascript:handlemailto( mailto:ncl-talk@mailman.ucar.edu );return false;');return false;">ncl-talk@mailman.ucar.edu</a>
          <br> Data: 10-mar-2021 0.11 
          <br> A: < 
          <a href="javascript:handleMailto('mailto:_javascript:handlemailto( mailto:ncl-talk@ucar.edu );return false;');return false;">ncl-talk@ucar.edu</a>> 
          <br> Ogg: [ncl-talk] Drawing several polygons on a xy plot 
          <br>
          <br>
          <font face="tahoma, arial, helvetica, sans-serif" style="font-family: tahoma , arial , helvetica , sans-serif;font-size: 12.0px;"><span style="font-size: 12.0px;">Dear NCL people,</span></font>
          <div style="font-family: tahoma , arial , helvetica , sans-serif;font-size: 12.0px;">
           <br>
          </div>
          <div style="font-family: tahoma , arial , helvetica , sans-serif;font-size: 12.0px;">
            I'm trying to draw several polygons on a time series plot, to obtain something like this ( 
           <a href="https://www.nature.com/articles/nclimate2106/figures/1">https://www.nature.com/articles/nclimate2106/figures/1</a>). Basically, I need separate filled boxes to be drawn anywhere the IPO index is negative. I'd like to not draw individual polygons myself, because I should set the x and y ranges explicitly. (That is, at all times when the IPO index changes sign). Rather, I'd like the boxes to be drawn automatically, without knowing where the index is negative. 
          </div>
          <div style="font-family: tahoma , arial , helvetica , sans-serif;font-size: 12.0px;">
           <br>
          </div>
          <div style="font-family: tahoma , arial , helvetica , sans-serif;font-size: 12.0px;">
            So far, my best attempt at the problem is to create a 1-D mask, setting all positive value of the index to missing values. Then, I'm creating one big box over the whole domain, relying on the missing values of the masked time series. The relevant snippet of my code is shown here. 
          </div>
          <div style="font-family: tahoma , arial , helvetica , sans-serif;font-size: 12.0px;">
           <br>
          </div>
          <div>
           <div>
            <div>
             <font face="tahoma, arial, helvetica, sans-serif"><span style="font-size: 12.0px;">;; Create polygons where AMIP II TPI/IPO index is negative</span></font>
            </div>
            <div>
             <font face="tahoma, arial, helvetica, sans-serif"><span style="font-size: 12.0px;"> temp_amip2_tpi_year_filter_neg = where(temp_amip2_tpi_year_filter.lt.0.,temp_amip2_tpi_year_filter,temp_amip2_tpi_year_filter@_FillValue)</span></font>
            </div>
            <div>
             <font face="tahoma, arial, helvetica, sans-serif"><span style="font-size: 12.0px;"> temp_amip2_tpi_year_filter_neg_xp = new((/2*nyear/),typeof(temp_amip2_tpi_year_filter_neg),temp_amip2_tpi_year_filter_neg@_FillValue)</span></font>
            </div>
            <div>
             <font face="tahoma, arial, helvetica, sans-serif"><span style="font-size: 12.0px;"> temp_amip2_tpi_year_filter_neg_yp = new((/2*nyear/),typeof(temp_amip2_tpi_year_filter_neg),temp_amip2_tpi_year_filter_neg@_FillValue)</span></font>
            </div>
            <div>
             <font face="tahoma, arial, helvetica, sans-serif"><span style="font-size: 12.0px;">do i = 0, nyear-1</span></font>
            </div>
            <div>
             <font face="tahoma, arial, helvetica, sans-serif"><span style="font-size: 12.0px;"> temp_amip2_tpi_year_filter_neg_yp(i)          = temp_amip2_tpi_year_filter_neg(i)+1.e2</span></font>
            </div>
            <div>
             <font face="tahoma, arial, helvetica, sans-serif"><span style="font-size: 12.0px;"> temp_amip2_tpi_year_filter_neg_xp(i)          = years(i)</span></font>
            </div>
            <div>
             <font face="tahoma, arial, helvetica, sans-serif"><span style="font-size: 12.0px;"> temp_amip2_tpi_year_filter_neg_xp(2*nyear-1-i) = years(i)</span></font>
            </div>
            <div>
             <font face="tahoma, arial, helvetica, sans-serif"><span style="font-size: 12.0px;"> temp_amip2_tpi_year_filter_neg_yp(2*nyear-1-i) = temp_amip2_tpi_year_filter_neg(i)-1.e2</span></font>
            </div>
            <div>
             <font face="tahoma, arial, helvetica, sans-serif"><span style="font-size: 12.0px;">end do</span></font>
            </div>
           </div>
          </div>
          <div style="font-family: tahoma , arial , helvetica , sans-serif;font-size: 12.0px;">
           <br>
          </div>
          <div style="font-family: tahoma , arial , helvetica , sans-serif;font-size: 12.0px;">
            After, I'm calling gsn_add_polygon to draw the boxes over the time series plot, but I'm getting only one big box (see attached). It seems that the function doesn't care about missing values, and in the description that's clearly stated ("If a missing value is encountered in 
           <em>x</em> and/or 
           <em>y</em>, then this pair is ignored, but the polygon will still be closed"; 
           <a href="https://www.ncl.ucar.edu/Document/Graphics/Interfaces/gsn_add_polygon.shtml">https://www.ncl.ucar.edu/Document/Graphics/Interfaces/gsn_add_polygon.shtml</a>). 
          </div>
          <div style="font-family: tahoma , arial , helvetica , sans-serif;font-size: 12.0px;">
           <br>
          </div>
          <div style="font-family: tahoma , arial , helvetica , sans-serif;font-size: 12.0px;">
            My question: is there a way to make gsn_add_polygon not closing the polygon? Is there a better way to draw those polygons with NCL? 
          </div>
          <div style="font-family: tahoma , arial , helvetica , sans-serif;font-size: 12.0px;">
           <br>
          </div>
          <div style="font-family: tahoma , arial , helvetica , sans-serif;font-size: 12.0px;">
            Best, 
          </div>
          <div style="font-family: tahoma , arial , helvetica , sans-serif;font-size: 12.0px;">
            Giorgio 
          </div>
         </blockquote>
        </div>
       </blockquote>
      </div>
     </div>
    </div>
   </blockquote>
  </div>
 </div>
 <br>
</blockquote>
<br></div>