<div dir="ltr"><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">First: you want to make sure gsnSpreadColors is *not* set at all.  When you use cnFillPalette, you shouldn&#39;t need the gsnSpreadXXXX resources.You&#39;ve already made sure you have the exact number of colors that you need for your contour levels, so you&#39;re good there.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">The issue is that NCL always contours the data based on values that fall between the given levels, and not exactly at the given levels.  So, for example, if you have data values that fall exactly at values 1, 2, 3, 4, 5, then to create contours at these values, you need to use values that fall between them:</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">res@cnLevels = (/1.5, 2.5, 3.5, 4.5 /)</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">With four contour levels, you will get five colors in your labelbar:</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small"> - the first color in your labelbar represents all values &lt;1.5 (hence covering the value 1)</div><div class="gmail_default" style="font-size:small"> - the second color will represent all values &gt;= 1.5 and &lt; 2.5 (hence covering the value 2)</div><div class="gmail_default" style="font-size:small">. . .</div><div class="gmail_default" style="font-size:small"> - the last (fifth) color will represent all values &gt; 4.5</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">If you look at the original vegland_1.ncl script, it is setting the levels to go from 2 to 18 in steps of 1, but the actual label strings go from 1 to 18 in steps of one.  This works because then the first color then represents all values &lt; 2 (thus catching the values equal to 1), and so on. I just like to use values like 1.5, 2.5, etc, to make it more clear, but the end result is the same.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">I think the rest of your resources for setting up centered-labels and setting the label strings themselves looks good.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">One final comment: gsn_panel only rearranges the existing plots and adds a labelbar, if requested.  It does *not* change the existing plots. Thus, the &quot;cnLevel&quot; resource will not be recognized by gsn_panel.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">Also, to make sure you get every box labeled, make sure you set:</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small"><div style="font-size:12.8px">  pres@lbLabelStride    = 1</div><div style="font-size:12.8px">  pres@lbLabelAutoStride = False</div><div style="font-size:12.8px"><br></div></div><div class="gmail_default" style="font-size:small">--Mary</div><div class="gmail_default" style="font-size:small"><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Sep 23, 2015 at 8:43 PM, dyjbean soybean <span dir="ltr">&lt;<a href="mailto:dyjbean@gmail.com" target="_blank">dyjbean@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">hi,<div>  i have made a landcover map, which includes indices from 1 to 19 and 31-32 , all is 22 categories.<div><br></div><div>but after i ploted them, only the 1 to 19 and 33 category appearing in figure, but the 31-32 these two category cannot be shown in figure.</div><div><br></div>those below is my NCL script:
</div><div><br></div><div><br></div><div>++++++++++++++++++++++++++++++++++</div><div><div><br></div><div>load &quot;$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl&quot;</div><div>load &quot;$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl&quot;</div><div>load &quot;$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl&quot;</div><div>load &quot;$NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl&quot;</div><div>load &quot;./shapefile_mask_data.ncl&quot;</div><div><br></div><div>begin</div><div>forgname=&quot;globecover_hubei_liuhuan_usgs_ronghe_snow-ice1.txt&quot;</div><div>fconname=&quot;globecover_huabei_liuhuan_usgs_new_allocate1.txt&quot;</div><div><br></div><div>onlat=5403</div><div>omlon=5403</div><div><br></div><div>nnlat=1801</div><div>nmlon=1801</div><div><br></div><div>odat=new((/onlat,omlon/),&quot;integer&quot;,&quot;No_FillValue&quot;)</div><div>ndat=new((/nnlat,nmlon/),&quot;integer&quot;,&quot;No_FillValue&quot;)</div><div><br></div><div>odat=readAsciiTable(forgname,omlon,&quot;integer&quot;,5)</div><div>ndat=asciiread(fconname,(/nnlat,nmlon/),&quot;integer&quot;)</div><div>delete(odat@_FillValue)</div><div>delete(ndat@_FillValue)</div><div><br></div><div>;; confused lc</div><div>olat=new((/onlat/),&quot;float&quot;,&quot;No_FillValue&quot;)</div><div>olon=new((/omlon/),&quot;float&quot;,&quot;No_FillValue&quot;)</div><div><br></div><div>do i=0,onlat-1</div><div> olat(i)=45.00413067-i*0.0027778</div><div>end do</div><div><br></div><div><br></div><div>do j=0,omlon-1</div><div> olon(j)=109.99606533+j*0.0027778</div><div>end do</div><div><br></div><div>olat!0=&quot;lat&quot;</div><div>olat@units=&quot;degrees_north&quot;</div><div>olat@long_name=&quot;latitude&quot;</div><div><br></div><div>olon!0=&quot;lon&quot;</div><div>olon@units=&quot;degrees_east&quot;</div><div>olon@long_name=&quot;longitude&quot;</div><div><br></div><div>odat!0=&quot;lat&quot;</div><div>odat!1=&quot;lon&quot;</div><div>odat&amp;lat=olat</div><div>odat&amp;lon=olon</div><div>odat@units=&quot;&quot;</div><div>odat@long_name=&quot;land cover confused with globaland30 and globercover&quot;</div><div>odat@_FillValue = -999</div><div><br></div><div>;; new classified lc</div><div>nlat=new((/nnlat/),&quot;float&quot;,&quot;No_FillValue&quot;)</div><div>nlon=new((/nmlon/),&quot;float&quot;,&quot;No_FillValue&quot;)</div><div><br></div><div>do i=0,nnlat-1</div><div> nlat(i)=45.00413067-i*0.0083334</div><div>end do</div><div><br></div><div><br></div><div>do j=0,nmlon-1</div><div> nlon(j)=109.99606533+j*0.0083334</div><div>end do</div><div><br></div><div>nlat!0=&quot;lat&quot;</div><div>nlat@units=&quot;degrees_north&quot;</div><div>nlat@long_name=&quot;latitude&quot;</div><div><br></div><div>nlon!0=&quot;lon&quot;</div><div>nlon@units=&quot;degrees_east&quot;</div><div>nlon@long_name=&quot;longitude&quot;</div><div><br></div><div>ndat!0=&quot;lat&quot;</div><div>ndat!1=&quot;lon&quot;</div><div>ndat&amp;lat=nlat</div><div>ndat&amp;lon=nlon</div><div>ndat@units=&quot;&quot;</div><div>ndat@long_name=&quot;land cover new categories after confused&quot;</div><div>ndat@_FillValue = -999</div><div><br></div><div>print(odat(onlat-1,omlon-1))</div><div><br></div><div>;</div><div>; If you already have the mask NetCDF file, set this to False.</div><div>; Creating the mask can be slow!</div><div>;</div><div>   CREATE_MASK = True</div><div><br></div><div>;---Whether to draw lat/lon points and shapefile outlines</div><div>   ADD_LATLON_POINTS      = False</div><div>   ADD_SHAPEFILE_OUTLINES = True</div><div><br></div><div>;---Name of shapefile containing USA outlines</div><div>   shp_fname = &quot;huan_6.shp&quot;</div><div><br></div><div>;---Name of file to write mask to or to read mask from.</div><div>   mask_oname = &quot;<a href="http://liuhuan_mask_300m.nc" target="_blank">liuhuan_mask_300m.nc</a>&quot;</div><div>   mask_nname = &quot;<a href="http://liuhuan_mask_1km.nc" target="_blank">liuhuan_mask_1km.nc</a>&quot;</div><div><br></div><div>;---Rough area we are interested in. Everything outside this will be masked.</div><div>   minlon = 116.0</div><div>   maxlon = 116.8</div><div>   minlat =   39.6</div><div>   maxlat =   40.2</div><div><br></div><div>;; odat</div><div>if(CREATE_MASK) then</div><div>     print(&quot;Creating the mask file...&quot;)</div><div><br></div><div>;---Create a new mask using a shapefile of USA</div><div>     odims = dimsizes(odat)</div><div>     opto             = True</div><div>     opto@return_mask = True</div><div>;    opto@debug       = True</div><div>     opto@minlon      = minlon     ; Makes the shapefile masking</div><div>     opto@maxlon      = maxlon     ; go faster.</div><div>     opto@minlat      = minlat</div><div>     opto@maxlat      = maxlat</div><div>     odat_mask        = shapefile_mask_data(odat,shp_fname,opto)</div><div><br></div><div>;---Write new mask to file</div><div>     system(&quot;rm -f &quot; + mask_oname)</div><div>     oout           = addfile(mask_oname,&quot;c&quot;)</div><div>     oout-&gt;odat_mask = odat_mask</div><div>   else</div><div>     print(&quot;Reading mask off file.&quot;)</div><div><br></div><div>;---Read the new mask from the NetCDF file</div><div>     omask    = addfile(mask_oname,&quot;r&quot;)</div><div>     odat_mask = omask-&gt;odat_mask</div><div>   end if</div><div><br></div><div>;; ndat</div><div>if(CREATE_MASK) then</div><div>     print(&quot;Creating the mask file...&quot;)</div><div><br></div><div>;---Create a new mask using a shapefile of USA</div><div>     ndims = dimsizes(ndat)</div><div>     optn             = True</div><div>     optn@return_mask = True</div><div>;    optn@debug       = True</div><div>     optn@minlon      = minlon     ; Makes the shapefile masking</div><div>     optn@maxlon      = maxlon     ; go faster.</div><div>     optn@minlat      = minlat</div><div>     optn@maxlat      = maxlat</div><div>     ndat_mask        = shapefile_mask_data(ndat,shp_fname,optn)</div><div><br></div><div>;---Write new mask to file</div><div>     system(&quot;rm -f &quot; + mask_nname)</div><div>     nout           = addfile(mask_nname,&quot;c&quot;)</div><div>     nout-&gt;ndat_mask = ndat_mask</div><div>   else</div><div>     print(&quot;Reading mask off file.&quot;)</div><div><br></div><div>;---Read the new mask from the NetCDF file</div><div>     nmask    = addfile(mask_nname,&quot;r&quot;)</div><div>     ndat_mask = nmask-&gt;ndat_mask</div><div>   end if</div><div><br></div><div>;---Create masked data array</div><div>   omask = where(odat_mask.eq.1,odat,odat@_FillValue)</div><div>   copy_VarMeta(odat,omask)</div><div><br></div><div>;---Create masked data array</div><div>   nmask = where(ndat_mask.eq.1,ndat,ndat@_FillValue)</div><div>   copy_VarMeta(ndat,nmask)</div><div><br></div><div><br></div><div>  ;ind32=ind(ndtooned(nmask).eq.32)</div><div>  ;print(ind32)</div><div><br></div><div>  dimsnmk=dimsizes(nmask)</div><div>  do i=0,dimsnmk(0)-1</div><div>    do j=0,dimsnmk(1)-1</div><div>       if(any(ndat(i,j).eq.32)) then</div><div>          print(i+&quot; &quot;+j+&quot; &quot;+&quot; &quot;+ndat(i,j))</div><div>       end if</div><div>    end do</div><div>  end do</div><div><br></div><div>;;;;;;;;;;;;;;;;;;;;;;;;;;;;</div><div>;; create plot</div><div>;;;;;;;;;;;;;;;;;;;;;;;;;;;;</div><div>plot=new(2,&quot;graphic&quot;)</div><div>info=(/                        \</div><div>      &quot;1 urban_and_built-in&quot;   ,\</div><div>      &quot;2 dryland_cropland&quot;     ,\</div><div>      &quot;3 irrigated_cropland&quot;   ,\</div><div>      &quot;4 mixed_dry_cropland&quot;   ,\</div><div>      &quot;5 cropland_grassland&quot;   ,\</div><div>      &quot;6 cropland_woodland&quot;    ,\</div><div>      &quot;7 grassland&quot;            ,\</div><div>      &quot;8 shrubland&quot;            ,\</div><div>      &quot;9 mixed_shrub_grassland&quot;,\</div><div>      &quot;10 savanna&quot;              ,\</div><div>      &quot;11 deciduous_broadleaf&quot;  ,\</div><div>      &quot;12 deciduous_needleleaf&quot; ,\</div><div>      &quot;13 evergreen_broadleaf&quot;  ,\</div><div>      &quot;14 evergreen_needleleaf&quot; ,\</div><div>      &quot;15 mixed_forest&quot;         ,\</div><div>      &quot;16 water&quot;                ,\</div><div>      &quot;17 herbaceous_wetland&quot;   ,\</div><div>      &quot;18 wooded_wetland&quot;       ,\</div><div>      &quot;19 barren_or_sparse&quot;     ,\</div><div>      &quot;31 low_intensity_res&quot;    ,\</div><div>      &quot;32 mid_intensity_res&quot;    ,\</div><div>      &quot;33 high_intensity_res&quot;/)</div><div><br></div><div>ninfo=dimsizes(info)</div><div><br></div><div>  ninfo = dimsizes(info)        ; # of classifications</div><div><br></div><div><br></div><div>;************************************************</div><div>; create plot</div><div>;************************************************</div><div>  pltType = &quot;png&quot;               ; ps, pdf, png, x11, eps</div><div><br></div><div><br></div><div><br></div><div>  colorscheme =(/&quot;red&quot;,&quot;lawngreen&quot;,&quot;mediumseagreen&quot;,&quot;springgreen&quot;,\</div><div>       &quot;limegreen&quot;,&quot;darkolivegreen3&quot;,&quot;green&quot;,&quot;lightsalmon&quot;,&quot;green3&quot;,\</div><div>        &quot;gold&quot;,&quot;palegreen&quot;,&quot;olivedrab3&quot;,&quot;chartreuse3&quot;,&quot;chartreuse&quot;,       \</div><div>        &quot;darkgreen&quot;,&quot;blue&quot;,&quot;hotpink2&quot;,&quot;hotpink&quot;,&quot;light cyan&quot;,           \</div><div>        &quot;khaki1&quot;,&quot;violetred1&quot;,&quot;purple3&quot;/)</div><div><br></div><div>  ncolors = dimsizes(colorscheme)</div><div>  if (ninfo.ne.ncolors) then             ; make sure # of colors match categories (classes)</div><div>      print(&quot;size mismatch: ninfo=&quot;+ninfo+&quot;   ncolors=&quot;+ncolors)</div><div>      exit</div><div>  end if</div><div><br></div><div>  wks = gsn_open_wks(pltType,&quot;plot_origin_new_lc_test&quot;)</div><div>  plot=new(2,graphic)</div><div>  res                  = True                ; plot mods desired</div><div>  res@gsnDraw          = False</div><div>  res@gsnFrame         = False</div><div>  ;res@gsnMaximize      = True               ; ps, pdf</div><div>  res@gsnAddCyclic     = False</div><div><br></div><div>  ;res@mpMinLatF   = min(odat&amp;lat)</div><div>  ;res@mpMaxLatF   = max(odat&amp;lat)</div><div>  ;res@mpMinLonF   = min(odat&amp;lon)</div><div>  ;res@mpMaxLonF   = max(odat&amp;lon)</div><div><br></div><div>  res@cnFillOn         = True               ; color Fill</div><div>  res@cnFillMode       = &quot;RasterFill&quot;</div><div>  res@cnLinesOn        =  False             ; Turn off contour lines</div><div>  res@cnLineLabelsOn   =  False</div><div>  res@cnLevelSelectionMode = &quot;ExplicitLevels&quot; ; set explict contour levels</div><div>  res@cnLevels         = tobyte(ispan(1,ninfo-1,1)+1)</div><div>  res@cnFillPalette    = colorscheme        ; distinct colors for categories</div><div>  res@gsnSpreadColors  = False              ; use each color sequentially</div><div>  res@cnInfoLabelOn   = False</div><div><br></div><div><br></div><div>  res@mpFillOn         = False</div><div><br></div><div><br></div><div>  res@gsnAddCyclic   = False             ; regional data</div><div>  ;res@trGridType     = &quot;TriangularMesh&quot;</div><div>  res@tmXBLabelFontHeightF = 0.01        ; Make lon &amp; lat text smaller</div><div>  res@tmYLLabelFontHeightF = res@tmXBLabelFontHeightF</div><div><br></div><div>  res@gsnLeftString  = &quot;&quot;</div><div>  res@gsnRightString = &quot;&quot;</div><div><br></div><div>  res1  =  True</div><div>  res1  =  res</div><div>  res1@mpMinLatF   = minlat</div><div>  res1@mpMaxLatF   = maxlat</div><div>  res1@mpMinLonF   = minlon</div><div>  res1@mpMaxLonF   = maxlon</div><div><br></div><div>  res1@tmXBMode    = &quot;Explicit&quot;</div><div>  res1@tmXBValues   = (/116.0,116.1,116.2,116.3,116.4,116.5,116.6,116.7,116.8/)</div><div>  res1@tmXBLabels  =  (/&quot;116.0~S~o~N~E&quot;,&quot;116.1~S~o~N~E&quot;,&quot;116.2~S~o~N~E&quot;,&quot;116.3~S~o~N~E&quot;,&quot;116.4~S~o~N~E&quot;,&quot;116.5.0~S~o~N~E&quot;,\</div><div>                        &quot;116.6~S~o~N~E&quot;,&quot;116.7~S~o~N~E&quot;,&quot;116.8~S~o~N~E&quot;/)</div><div><br></div><div>  res1@tmYLMode    = &quot;Explicit&quot;</div><div>  res1@tmYLValues   = (/39.6,39.7,39.8,39.9,40.0,40.1,40.2/)</div><div>  res1@tmYLLabels  = (/&quot;39.6~S~o~N~N&quot;,&quot;39.7~S~o~N~N&quot;,&quot;39.8~S~o~N~N&quot;,&quot;39.9~S~o~N~N&quot;,&quot;40.0~S~o~N~N&quot;,&quot;40.1~S~o~N~N&quot;,&quot;41.2~S~o~N~N&quot;/)</div><div><br></div><div>  res1@tiMainString   = &quot;confused LC&quot;</div><div>  res1@lbLabelBarOn   =  False</div><div>  plot(0) = gsn_csm_contour_map_ce(wks, omask, res1) ; create plot</div><div><br></div><div>  res2 = True</div><div>  res2=res</div><div>  res2@mpMinLatF   = minlat</div><div>  res2@mpMaxLatF   = maxlat</div><div>  res2@mpMinLonF   = minlon</div><div>  res2@mpMaxLonF   = maxlon</div><div>  res2@lbLabelBarOn   =  False</div><div><br></div><div>  res2@tmXBMode    = &quot;Explicit&quot;</div><div>  res2@tmXBValues  = (/116.0,116.1,116.2,116.3,116.4,116.5,116.6,116.7,116.8/)</div><div>  res2@tmXBLabels  = (/&quot;116.0~S~o~N~E&quot;,&quot;116.1~S~o~N~E&quot;,&quot;116.2~S~o~N~E&quot;,&quot;116.3~S~o~N~E&quot;,&quot;116.4~S~o~N~E&quot;,&quot;116.5.0~S~o~N~E&quot;,\</div><div>                       &quot;116.6~S~o~N~E&quot;,&quot;116.7~S~o~N~E&quot;,&quot;116.8~S~o~N~E&quot;/)</div><div><br></div><div>  res2@tmYLMode    = &quot;Explicit&quot;</div><div>  res2@tmYLValues   = (/39.6,39.7,39.8,39.9,40.0,40.1,40.2/)</div><div>  res2@tmYLLabels  = (/&quot;39.6~S~o~N~N&quot;,&quot;39.7~S~o~N~N&quot;,&quot;39.8~S~o~N~N&quot;,&quot;39.9~S~o~N~N&quot;,&quot;40.0~S~o~N~N&quot;,&quot;40.1~S~o~N~N&quot;,&quot;41.2~S~o~N~N&quot;/)</div><div><br></div><div>  res2@tiMainString =  &quot;reclassified LC&quot;</div><div>  plot(1) =  gsn_csm_contour_map_ce(wks,nmask,res2)</div><div><br></div><div>  pres = True</div><div>  pres@gsnFrame =  False</div><div>  pres@gsnPanelLabelBar  = True</div><div>  pres@lbLabelFontHeightF = 0.01</div><div>  pres@gsnPanelBottom = 0.05</div><div>  pres@lbLabelPosition  = &quot;Center&quot;           ; label position</div><div>  pres@lbLabelAlignment = &quot;BoxCenters&quot;       ; label orientation</div><div>  pres@cnLevels   =  (/1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,\</div><div>                       31,32,33/)</div><div>  pres@lbLabelStrings    = (/&quot;1&quot;,&quot;2&quot;,&quot;3&quot;,&quot;4&quot;,&quot;5&quot;,&quot;6&quot;,&quot;7&quot;,&quot;8&quot;,&quot;9&quot;,&quot;10&quot;,\</div><div>                           &quot;11&quot;,&quot;12&quot;,&quot;13&quot;,&quot;14&quot;,&quot;15&quot;,&quot;16&quot;,&quot;17&quot;,&quot;18&quot;,&quot;19&quot;,\</div><div>                           &quot;31&quot;,&quot;32&quot;,&quot;33&quot;/)</div><div> ;pres@lbLabelStrings   = ispan(0,ninfo,1)</div><div>  ;pres@lbLabelStride    = 1</div><div>  pres@lbLabelAutoStride = True</div><div><br></div><div>  gsn_panel(wks,plot,(/1,2/),pres)</div><div><br></div><div>  rtxt = True</div><div>  rtxt@txJust        = &quot;TopLeft&quot;</div><div>  rtxt@txFontHeightF = 0.0125</div><div><br></div><div>  ; Add text: rows x columns of text (arbitrary)</div><div>; Usually must play with xx, yy and txFontHeightF</div><div><br></div><div>  nrow = 5       ; # rows</div><div>  ncol = 6       ; # columns</div><div><br></div><div>  n  = -1</div><div>  xx = 0.015                ; arbitrary</div><div>  do nc=0,ncol-1</div><div>     yy = 0.20</div><div>    do nr=0,nrow-1</div><div>       n = n+1</div><div>       if (n.le.(ninfo-1)) then</div><div>           gsn_text_ndc (wks,info(n),xx,yy,rtxt)</div><div>           yy = yy - 2*rtxt@txFontHeightF</div><div>       end if</div><div>    end do</div><div>    xx = xx + 0.20</div><div>  end do</div><div><br></div><div> ;draw(plot)</div><div> frame(wks)</div><div><br></div><div>end</div></div><div><br></div><div><br></div><div><br></div><div>++++++++++++++++++++++++++++++++++</div><div><br></div><div>i don&#39;t know  if the nested pic can show, so i attach it </div><div><br></div><div>i change the urban (denote with red color in left panel)  into impervious category (31,32,33,show in right panel), but eventually only 33 appeared, 31 and 32 disappeared.</div><div>the 31-32 exists in data.</div><div><br></div><div>can the ncl script  match the landcover index automatically?</div><div><br></div><div><br></div><div>would you please give me some advices for this problem which i have been confused some days?</div><div><br></div><div>thanks</div></div>
<br>_______________________________________________<br>
ncl-talk mailing list<br>
<a href="mailto:ncl-talk@ucar.edu">ncl-talk@ucar.edu</a><br>
List instructions, subscriber options, unsubscribe:<br>
<a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" rel="noreferrer" target="_blank">http://mailman.ucar.edu/mailman/listinfo/ncl-talk</a><br>
<br></blockquote></div><br></div>