[ncl-talk] Dividing a legend over 2 cells in a matrix plot

Adam Phillips asphilli at ucar.edu
Mon Jul 30 13:28:47 MDT 2018


Hi Toni,
You should not need to call gsn_create_legend if you are using
simple_legend_ndc. Thus, I would comment out that portion of the code.
(Note too that gsn_create_legend returns a plot object that must be
attached to a plot for the legend to be shown; I don't see where in your
code that you are doing that. See legend example #8 here:
https://www.ncl.ucar.edu/Applications/legend.shtml#ex8.)

Assuming that the legend shown in your plot is being created by
simple_legend_ndc, you have complete control over how the legend looks by
adjusting the 3 resource lists as is shown in the documentation here:
https://www.ncl.ucar.edu/Document/Functions/Shea_util/simple_legend_ndc.shtml

Specifically, see Example 2 for a complete list of all resources that are
accepted by the procedure. In your coding you have some resources set that
are not accepted by simple_legend_ndc (vpHeightF/vpWidthF, for example). To
alter the spacing between the labels for instance, set:
 gres at ItemSpacePercent = 1.
You will need to set many of the resources set in Example 2 to get your
legend looking the way you want. This will likely take some trial and error
on your part.
Adam


On Mon, Jul 30, 2018 at 12:45 PM Toni Klemm <toni-klemm at tamu.edu> wrote:

> Hi Adam,
>
> The legend now appears in the plot matrix, but it’s too large and overlaps
> with the other plots. I attached it again.
>
> I tried to incorporate your suggestions as best I could, but I my script
> structure might be different from yours, so I might have done it wrong. I
> included my script below.
>
> I used lgLabelFontHeightF, vpWidthF, and vpHeightF at the end of the
> script to reduce the size but it didn’t work. I also set lgAutoManage =
> False , just in case, but I still wasn’t able to change the size.
>
> Thank you again for your help!
>
> Toni
>
>
>
> *Toni Klemm, Ph.D.*Postdoctoral Research Associate
> Department of Ecosystem Science and Management
> Texas A&M University, College Station, TX
> Contributor at the Early Career Climate Forum <http://www.eccforum.org>
> www.toni-klemm.de | @toniklemm <http://twitter.com/toniklemm>
>
>
>
> ; Create time series plots of NPP stored in the 9 different functional
> groups in each climate zone
> ; 9 groups per plot, 16 plots (zones) per matrix
>
> ; ---------------------------------------------------
>
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
> load "~/NIFA/NCL_6.5.0_functions/simple_legend_ndc.ncl"
>
> ; ---------------------------------------------------
>
> begin
>
> RCP_list = [/"rcp_45","rcp_85"/]
> fs_list = [/"fs","nfs"/]
> model_list =
> [/"CCSM4","GFDL-ESM2M","HadGEM2-ES365","IPSL-CM5A-LR","MRI-CGCM3"/]
>
> RCP_title = [/"RCP 4.5","RCP 8.5"/]
> fs_title = [/"Fire Suppr. on","Fire Suppr. off"/]
> model_title =
> [/"CCSM4","GFDL-ESM2M","HadGEM2-ES365","IPSL-CM5A-LR","MRI-CGCM3"/]
>
> do h = 0, ListCount(RCP_list) - 1
>
>   do i = 0, ListCount(fs_list) - 1
>
>     do j = 0, ListCount(model_list) - 1
>
>
>   ; ***********************************************
>   ; 1 - READ IN MC2 FILE
>   ; ***********************************************
>
> print("")
> print("~/NIFA/MC2/subset_climate_zones/" + RCP_list[h](0) + "/" +
> fs_list[i](0) + "/" + model_list[j](0))
>   print("1 - Read in files")
> diri = "~/NIFA/MC2/subset_climate_zones/" + RCP_list[h](0) + "/" +
> fs_list[i](0) + "/" + model_list[j](0) + "/NPP_GROUPED/"
>
>   zone_01_f = addfile(diri + RCP_list[h](0) + "_" + fs_list[i](0) + "_" +
> model_list[j](0) + "_NPP_grouped_zone_01.nc","r")
>   zone_02_f = addfile(diri + RCP_list[h](0) + "_" + fs_list[i](0) + "_" +
> model_list[j](0) + "_NPP_grouped_zone_02.nc","r")
>   zone_03_f = addfile(diri + RCP_list[h](0) + "_" + fs_list[i](0) + "_" +
> model_list[j](0) + "_NPP_grouped_zone_03.nc","r")
>   zone_04_f = addfile(diri + RCP_list[h](0) + "_" + fs_list[i](0) + "_" +
> model_list[j](0) + "_NPP_grouped_zone_04.nc","r")
>   zone_05_f = addfile(diri + RCP_list[h](0) + "_" + fs_list[i](0) + "_" +
> model_list[j](0) + "_NPP_grouped_zone_05.nc","r")
>   zone_06_f = addfile(diri + RCP_list[h](0) + "_" + fs_list[i](0) + "_" +
> model_list[j](0) + "_NPP_grouped_zone_06.nc","r")
>   zone_07_f = addfile(diri + RCP_list[h](0) + "_" + fs_list[i](0) + "_" +
> model_list[j](0) + "_NPP_grouped_zone_07.nc","r")
>   zone_08_f = addfile(diri + RCP_list[h](0) + "_" + fs_list[i](0) + "_" +
> model_list[j](0) + "_NPP_grouped_zone_08.nc","r")
>   zone_09_f = addfile(diri + RCP_list[h](0) + "_" + fs_list[i](0) + "_" +
> model_list[j](0) + "_NPP_grouped_zone_09.nc","r")
>   zone_10_f = addfile(diri + RCP_list[h](0) + "_" + fs_list[i](0) + "_" +
> model_list[j](0) + "_NPP_grouped_zone_10.nc","r")
>   zone_11_f = addfile(diri + RCP_list[h](0) + "_" + fs_list[i](0) + "_" +
> model_list[j](0) + "_NPP_grouped_zone_11.nc","r")
>   zone_12_f = addfile(diri + RCP_list[h](0) + "_" + fs_list[i](0) + "_" +
> model_list[j](0) + "_NPP_grouped_zone_12.nc","r")
>   zone_13_f = addfile(diri + RCP_list[h](0) + "_" + fs_list[i](0) + "_" +
> model_list[j](0) + "_NPP_grouped_zone_13.nc","r")
>   zone_14_f = addfile(diri + RCP_list[h](0) + "_" + fs_list[i](0) + "_" +
> model_list[j](0) + "_NPP_grouped_zone_14.nc","r")
>   zone_15_f = addfile(diri + RCP_list[h](0) + "_" + fs_list[i](0) + "_" +
> model_list[j](0) + "_NPP_grouped_zone_15.nc","r")
>   zone_16_f = addfile(diri + RCP_list[h](0) + "_" + fs_list[i](0) + "_" +
> model_list[j](0) + "_NPP_grouped_zone_16.nc","r")
>
>
>   ; ***********************************************
>   ; 2 - CREATE MATRIX PLOT
>   ; ***********************************************
>
>   print("2 - Create Plot Matrix")
>
>   diro =
> "~/NIFA/MC2/subset_climate_zones/time_series/NPP/all_zones_all_groups/"
>   filo = RCP_list[h](0) + "_" + fs_list[i](0) + "_" + model_list[j](0) +
> "_NPP_percentage_all_zones_all_groups_TEST_simple_legend_ndc"
>
>   wks_type = "png"          ; plot file type
>   wks_type at wkWidth = 3500   ; width dimension
>   wks_type at wkHeight = 3500  ; height dimension
>
>   wks = gsn_open_wks(wks_type, diro + filo)
>
>   gsn_define_colormap(wks,"wgne15")     ; define colormap
>
>
>   ;*********************************************
>   ; PLOT MATRIX PARAMETERS
>   ;*********************************************
>
>   res               = True
>   res at trYMinF       = 0 ; min  y axis value
>   res at trYMaxF       = 100 ; max  y axis value
>   res at trXMinF       = 2015     ; min  y axis value
>   res at trXMaxF       = 2100     ; max  x axis value
>   res at tmXBMinorOn   = True ; turn off minor tickmarks
>   res at tmYLMinorOn   = True
>   res at tmXTOn        = False ; turn off top tickmarks
>   res at tmYROn        = False ; turn off right tickmarks
>   res at tmXTBorderOn  = False ; turn off top axis
>   res at tmYRBorderOn  = False ; turn off right axis
>
>   res at tiXAxisString = "Years" ; titles
>   res at tiYAxisString = "%"
>
>
>   res at tmYLLabelFontHeightF       = 0.03 ; set font heights
>   res at gsnRightStringFontHeightF  = 0.03
>   res at tiXAxisFontHeightF         = 0.03
>   res at tiYAxisFontHeightF         = 0.03
>
>   res at vpWidthF       = .8  ; change aspect ratio
>   res at vpHeightF      = .4
>
>   res at gsnDraw       = False ; don't draw or advance the frame
>   res at gsnFrame      = False
>
> res at xyDashPattern  = 0 ; Make curves all solid
> res at xyLineColors :=
> (/"blue","red","orange","black","green","pink","brown","purple","grey"/) ;
> 9 different colors
> res at xyLineThicknesses = (/10,10,10,10,10,10,10,10,10/) ; make second line
> thicker
>
>
>   plot = new(18,graphic)                ; create 18-plot array
>   x    = (/0,1/) ; arrays for fack axis
>   y    = (/0,0/)
>
>   do gg = 0,15
>     plot(gg) = gsn_csm_xy(wks,x,y,res)
>   end do
>
>
> ;*********************************************
> ; READ IN PLOT VARIABLES
> ;*********************************************
>
>   print("3 - Read in plot variables")
>
> year = zone_01_f->year
>
> units = "%"
>
> data_01 = new((/9,dimsizes(year)/),float) ; data array for 9 variables
> and 85 years of record (2015-2099)
> data_02 = new((/9,dimsizes(year)/),float) ; data array for 9 variables
> and 85 years of record (2015-2099)
> data_03 = new((/9,dimsizes(year)/),float) ; data array for 9 variables
> and 85 years of record (2015-2099)
> data_04 = new((/9,dimsizes(year)/),float) ; data array for 9 variables
> and 85 years of record (2015-2099)
> data_05 = new((/9,dimsizes(year)/),float) ; data array for 9 variables
> and 85 years of record (2015-2099)
> data_06 = new((/9,dimsizes(year)/),float) ; data array for 9 variables
> and 85 years of record (2015-2099)
> data_07 = new((/9,dimsizes(year)/),float) ; data array for 9 variables
> and 85 years of record (2015-2099)
> data_08 = new((/9,dimsizes(year)/),float) ; data array for 9 variables
> and 85 years of record (2015-2099)
> data_09 = new((/9,dimsizes(year)/),float) ; data array for 9 variables
> and 85 years of record (2015-2099)
> data_10 = new((/9,dimsizes(year)/),float) ; data array for 9 variables
> and 85 years of record (2015-2099)
> data_11 = new((/9,dimsizes(year)/),float) ; data array for 9 variables
> and 85 years of record (2015-2099)
> data_12 = new((/9,dimsizes(year)/),float) ; data array for 9 variables
> and 85 years of record (2015-2099)
> data_13 = new((/9,dimsizes(year)/),float) ; data array for 9 variables
> and 85 years of record (2015-2099)
> data_14 = new((/9,dimsizes(year)/),float) ; data array for 9 variables
> and 85 years of record (2015-2099)
> data_15 = new((/9,dimsizes(year)/),float) ; data array for 9 variables
> and 85 years of record (2015-2099)
> data_16 = new((/9,dimsizes(year)/),float) ; data array for 9 variables
> and 85 years of record (2015-2099)
>
> print("3a   - Zone 1")
>
> data_01(0,:) = zone_01_f->NPP_C3G_percentage
> data_01(1,:) = zone_01_f->NPP_C3S_percentage
> data_01(2,:) = zone_01_f->NPP_C4G_percentage
> data_01(3,:) = zone_01_f->NPP_C4S_percentage
> data_01(4,:) = zone_01_f->NPP_OTHER_percentage
> data_01(5,:) = zone_01_f->NPP_SF_percentage
> data_01(6,:) = zone_01_f->NPP_SW_percentage
> data_01(7,:) = zone_01_f->NPP_TF_percentage
> data_01(8,:) = zone_01_f->NPP_TW_percentage
> ALL_data_01 = zone_01_f->NPP_ALL_annual
>
> print("3a   - Zone 2")
>
> data_02(0,:) = zone_02_f->NPP_C3G_percentage
> data_02(1,:) = zone_02_f->NPP_C3S_percentage
> data_02(2,:) = zone_02_f->NPP_C4G_percentage
> data_02(3,:) = zone_02_f->NPP_C4S_percentage
> data_02(4,:) = zone_02_f->NPP_OTHER_percentage
> data_02(5,:) = zone_02_f->NPP_SF_percentage
> data_02(6,:) = zone_02_f->NPP_SW_percentage
> data_02(7,:) = zone_02_f->NPP_TF_percentage
> data_02(8,:) = zone_02_f->NPP_TW_percentage
> ALL_data_02 = zone_02_f->NPP_ALL_annual
>
> print("3a   - Zone 3")
>
> data_03(0,:) = zone_03_f->NPP_C3G_percentage
> data_03(1,:) = zone_03_f->NPP_C3S_percentage
> data_03(2,:) = zone_03_f->NPP_C4G_percentage
> data_03(3,:) = zone_03_f->NPP_C4S_percentage
> data_03(4,:) = zone_03_f->NPP_OTHER_percentage
> data_03(5,:) = zone_03_f->NPP_SF_percentage
> data_03(6,:) = zone_03_f->NPP_SW_percentage
> data_03(7,:) = zone_03_f->NPP_TF_percentage
> data_03(8,:) = zone_03_f->NPP_TW_percentage
> ALL_data_03 = zone_03_f->NPP_ALL_annual
>
> print("3a   - Zone 4")
>
> data_04(0,:) = zone_04_f->NPP_C3G_percentage
> data_04(1,:) = zone_04_f->NPP_C3S_percentage
> data_04(2,:) = zone_04_f->NPP_C4G_percentage
> data_04(3,:) = zone_04_f->NPP_C4S_percentage
> data_04(4,:) = zone_04_f->NPP_OTHER_percentage
> data_04(5,:) = zone_04_f->NPP_SF_percentage
> data_04(6,:) = zone_04_f->NPP_SW_percentage
> data_04(7,:) = zone_04_f->NPP_TF_percentage
> data_04(8,:) = zone_04_f->NPP_TW_percentage
> ALL_data_04 = zone_04_f->NPP_ALL_annual
>
> print("3a   - Zone 5")
>
> data_05(0,:) = zone_05_f->NPP_C3G_percentage
> data_05(1,:) = zone_05_f->NPP_C3S_percentage
> data_05(2,:) = zone_05_f->NPP_C4G_percentage
> data_05(3,:) = zone_05_f->NPP_C4S_percentage
> data_05(4,:) = zone_05_f->NPP_OTHER_percentage
> data_05(5,:) = zone_05_f->NPP_SF_percentage
> data_05(6,:) = zone_05_f->NPP_SW_percentage
> data_05(7,:) = zone_05_f->NPP_TF_percentage
> data_05(8,:) = zone_05_f->NPP_TW_percentage
> ALL_data_05 = zone_05_f->NPP_ALL_annual
>
> print("3a   - Zone 6")
>
> data_06(0,:) = zone_06_f->NPP_C3G_percentage
> data_06(1,:) = zone_06_f->NPP_C3S_percentage
> data_06(2,:) = zone_06_f->NPP_C4G_percentage
> data_06(3,:) = zone_06_f->NPP_C4S_percentage
> data_06(4,:) = zone_06_f->NPP_OTHER_percentage
> data_06(5,:) = zone_06_f->NPP_SF_percentage
> data_06(6,:) = zone_06_f->NPP_SW_percentage
> data_06(7,:) = zone_06_f->NPP_TF_percentage
> data_06(8,:) = zone_06_f->NPP_TW_percentage
> ALL_data_06 = zone_06_f->NPP_ALL_annual
>
> print("3a   - Zone 7")
>
> data_07(0,:) = zone_07_f->NPP_C3G_percentage
> data_07(1,:) = zone_07_f->NPP_C3S_percentage
> data_07(2,:) = zone_07_f->NPP_C4G_percentage
> data_07(3,:) = zone_07_f->NPP_C4S_percentage
> data_07(4,:) = zone_07_f->NPP_OTHER_percentage
> data_07(5,:) = zone_07_f->NPP_SF_percentage
> data_07(6,:) = zone_07_f->NPP_SW_percentage
> data_07(7,:) = zone_07_f->NPP_TF_percentage
> data_07(8,:) = zone_07_f->NPP_TW_percentage
> ALL_data_07 = zone_07_f->NPP_ALL_annual
>
> print("3a   - Zone 8")
>
> data_08(0,:) = zone_08_f->NPP_C3G_percentage
> data_08(1,:) = zone_08_f->NPP_C3S_percentage
> data_08(2,:) = zone_08_f->NPP_C4G_percentage
> data_08(3,:) = zone_08_f->NPP_C4S_percentage
> data_08(4,:) = zone_08_f->NPP_OTHER_percentage
> data_08(5,:) = zone_08_f->NPP_SF_percentage
> data_08(6,:) = zone_08_f->NPP_SW_percentage
> data_08(7,:) = zone_08_f->NPP_TF_percentage
> data_08(8,:) = zone_08_f->NPP_TW_percentage
> ALL_data_08 = zone_08_f->NPP_ALL_annual
>
> print("3a   - Zone 9")
>
> data_09(0,:) = zone_09_f->NPP_C3G_percentage
> data_09(1,:) = zone_09_f->NPP_C3S_percentage
> data_09(2,:) = zone_09_f->NPP_C4G_percentage
> data_09(3,:) = zone_09_f->NPP_C4S_percentage
> data_09(4,:) = zone_09_f->NPP_OTHER_percentage
> data_09(5,:) = zone_09_f->NPP_SF_percentage
> data_09(6,:) = zone_09_f->NPP_SW_percentage
> data_09(7,:) = zone_09_f->NPP_TF_percentage
> data_09(8,:) = zone_09_f->NPP_TW_percentage
> ALL_data_09 = zone_09_f->NPP_ALL_annual
>
> print("3a   - Zone 10")
>
> data_10(0,:) = zone_10_f->NPP_C3G_percentage
> data_10(1,:) = zone_10_f->NPP_C3S_percentage
> data_10(2,:) = zone_10_f->NPP_C4G_percentage
> data_10(3,:) = zone_10_f->NPP_C4S_percentage
> data_10(4,:) = zone_10_f->NPP_OTHER_percentage
> data_10(5,:) = zone_10_f->NPP_SF_percentage
> data_10(6,:) = zone_10_f->NPP_SW_percentage
> data_10(7,:) = zone_10_f->NPP_TF_percentage
> data_10(8,:) = zone_10_f->NPP_TW_percentage
> ALL_data_10 = zone_10_f->NPP_ALL_annual
>
> print("3a   - Zone 11")
>
> data_11(0,:) = zone_11_f->NPP_C3G_percentage
> data_11(1,:) = zone_11_f->NPP_C3S_percentage
> data_11(2,:) = zone_11_f->NPP_C4G_percentage
> data_11(3,:) = zone_11_f->NPP_C4S_percentage
> data_11(4,:) = zone_11_f->NPP_OTHER_percentage
> data_11(5,:) = zone_11_f->NPP_SF_percentage
> data_11(6,:) = zone_11_f->NPP_SW_percentage
> data_11(7,:) = zone_11_f->NPP_TF_percentage
> data_11(8,:) = zone_11_f->NPP_TW_percentage
> ALL_data_11 = zone_11_f->NPP_ALL_annual
>
> print("3a   - Zone 12")
>
> data_12(0,:) = zone_12_f->NPP_C3G_percentage
> data_12(1,:) = zone_12_f->NPP_C3S_percentage
> data_12(2,:) = zone_12_f->NPP_C4G_percentage
> data_12(3,:) = zone_12_f->NPP_C4S_percentage
> data_12(4,:) = zone_12_f->NPP_OTHER_percentage
> data_12(5,:) = zone_12_f->NPP_SF_percentage
> data_12(6,:) = zone_12_f->NPP_SW_percentage
> data_12(7,:) = zone_12_f->NPP_TF_percentage
> data_12(8,:) = zone_12_f->NPP_TW_percentage
> ALL_data_12 = zone_12_f->NPP_ALL_annual
>
> print("3a   - Zone 13")
>
> data_13(0,:) = zone_13_f->NPP_C3G_percentage
> data_13(1,:) = zone_13_f->NPP_C3S_percentage
> data_13(2,:) = zone_13_f->NPP_C4G_percentage
> data_13(3,:) = zone_13_f->NPP_C4S_percentage
> data_13(4,:) = zone_13_f->NPP_OTHER_percentage
> data_13(5,:) = zone_13_f->NPP_SF_percentage
> data_13(6,:) = zone_13_f->NPP_SW_percentage
> data_13(7,:) = zone_13_f->NPP_TF_percentage
> data_13(8,:) = zone_13_f->NPP_TW_percentage
> ALL_data_13 = zone_13_f->NPP_ALL_annual
>
> print("3a   - Zone 14")
>
> data_14(0,:) = zone_14_f->NPP_C3G_percentage
> data_14(1,:) = zone_14_f->NPP_C3S_percentage
> data_14(2,:) = zone_14_f->NPP_C4G_percentage
> data_14(3,:) = zone_14_f->NPP_C4S_percentage
> data_14(4,:) = zone_14_f->NPP_OTHER_percentage
> data_14(5,:) = zone_14_f->NPP_SF_percentage
> data_14(6,:) = zone_14_f->NPP_SW_percentage
> data_14(7,:) = zone_14_f->NPP_TF_percentage
> data_14(8,:) = zone_14_f->NPP_TW_percentage
> ALL_data_14 = zone_14_f->NPP_ALL_annual
>
> print("3a   - Zone 15")
>
> data_15(0,:) = zone_15_f->NPP_C3G_percentage
> data_15(1,:) = zone_15_f->NPP_C3S_percentage
> data_15(2,:) = zone_15_f->NPP_C4G_percentage
> data_15(3,:) = zone_15_f->NPP_C4S_percentage
> data_15(4,:) = zone_15_f->NPP_OTHER_percentage
> data_15(5,:) = zone_15_f->NPP_SF_percentage
> data_15(6,:) = zone_15_f->NPP_SW_percentage
> data_15(7,:) = zone_15_f->NPP_TF_percentage
> data_15(8,:) = zone_15_f->NPP_TW_percentage
> ALL_data_15 = zone_15_f->NPP_ALL_annual
>
> print("3a   - Zone 16")
>
> data_16(0,:) = zone_16_f->NPP_C3G_percentage
> data_16(1,:) = zone_16_f->NPP_C3S_percentage
> data_16(2,:) = zone_16_f->NPP_C4G_percentage
> data_16(3,:) = zone_16_f->NPP_C4S_percentage
> data_16(4,:) = zone_16_f->NPP_OTHER_percentage
> data_16(5,:) = zone_16_f->NPP_SF_percentage
> data_16(6,:) = zone_16_f->NPP_SW_percentage
> data_16(7,:) = zone_16_f->NPP_TF_percentage
> data_16(8,:) = zone_16_f->NPP_TW_percentage
> ALL_data_16 = zone_16_f->NPP_ALL_annual
>
> ;*********************************************************
> ; CREATE INDIVIDUAL PLOTS
> ;*********************************************************
>
> print("4 - Create individual plots")
>
> print("4a   - Zone 1")
>
>   res at gsnRightString = "Zone 1" ; title
>   res at gsnLeftString  = "Avg.: "  +
> decimalPlaces(dim_avg_n(ALL_data_01,0)/1000000,1,True) + " t C m^-2"
> plot(0) = gsn_csm_xy (wks,year,data_01,res) ; create plot
> print("4a   - Zone 2")
>
>   res at gsnRightString = "Zone 2" ; title
>   res at gsnLeftString  = "Avg.: "  +
> decimalPlaces(dim_avg_n(ALL_data_02,0)/1000000,1,True) + " t C m^-2"
> plot(1) = gsn_csm_xy (wks,year,data_02,res) ; create plot
> print("4a   - Zone 3")
>
>   res at gsnRightString = "Zone 3" ; title
>   res at gsnLeftString  = "Avg.: "  +
> decimalPlaces(dim_avg_n(ALL_data_03,0)/1000000,1,True) + " t C m^-2"
> plot(2) = gsn_csm_xy (wks,year,data_03,res) ; create plot
> print("4a   - Zone 4")
>
>   res at gsnRightString = "Zone 4" ; title
>   res at gsnLeftString  = "Avg.: "  +
> decimalPlaces(dim_avg_n(ALL_data_04,0)/1000000,1,True) + " t C m^-2"
> plot(3) = gsn_csm_xy (wks,year,data_04,res) ; create plot
> print("4a   - Zone 5")
>
>   res at gsnRightString = "Zone 5" ; title
>   res at gsnLeftString  = "Avg.: "  +
> decimalPlaces(dim_avg_n(ALL_data_05,0)/1000000,1,True) + " t C m^-2"
> plot(4) = gsn_csm_xy (wks,year,data_05,res) ; create plot
> print("4a   - Zone 6")
>
>   res at gsnRightString = "Zone 6" ; title
>   res at gsnLeftString  = "Avg.: "  +
> decimalPlaces(dim_avg_n(ALL_data_06,0)/1000000,1,True) + " t C m^-2"
> plot(5) = gsn_csm_xy (wks,year,data_06,res) ; create plot
> print("4a   - Zone 7")
>
>   res at gsnRightString = "Zone 7" ; title
>   res at gsnLeftString  = "Avg.: "  +
> decimalPlaces(dim_avg_n(ALL_data_07,0)/1000000,1,True) + " t C m^-2"
> plot(6) = gsn_csm_xy (wks,year,data_07,res) ; create plot
> print("4a   - Zone 8")
>
>   res at gsnRightString = "Zone 8" ; title
>   res at gsnLeftString  = "Avg.: "  +
> decimalPlaces(dim_avg_n(ALL_data_08,0)/1000000,1,True) + " t C m^-2"
> plot(7) = gsn_csm_xy (wks,year,data_08,res) ; create plot
> print("4a   - Zone 9")
>
>   res at gsnRightString = "Zone 9" ; title
>   res at gsnLeftString  = "Avg.: "  +
> decimalPlaces(dim_avg_n(ALL_data_09,0)/1000000,1,True) + " t C m^-2"
> plot(8) = gsn_csm_xy (wks,year,data_09,res) ; create plot
> print("4a   - Zone 10")
>
>   res at gsnRightString = "Zone 10" ; title
>   res at gsnLeftString  = "Avg.: "  +
> decimalPlaces(dim_avg_n(ALL_data_10,0)/1000000,1,True) + " t C m^-2"
> plot(9) = gsn_csm_xy (wks,year,data_10,res) ; create plot
> print("4a   - Zone 11")
>
>   res at gsnRightString = "Zone 11" ; title
>   res at gsnLeftString  = "Avg.: "  +
> decimalPlaces(dim_avg_n(ALL_data_11,0)/1000000,1,True) + " t C m^-2"
> plot(10) = gsn_csm_xy (wks,year,data_11,res) ; create plot
> print("4a   - Zone 12")
>
>   res at gsnRightString = "Zone 12" ; title
>   res at gsnLeftString  = "Avg.: "  +
> decimalPlaces(dim_avg_n(ALL_data_12,0)/1000000,1,True) + " t C m^-2"
> plot(11) = gsn_csm_xy (wks,year,data_12,res) ; create plot
> print("4a   - Zone 13")
>
>   res at gsnRightString = "Zone 13" ; title
>   res at gsnLeftString  = "Avg.: "  +
> decimalPlaces(dim_avg_n(ALL_data_13,0)/1000000,1,True) + " t C m^-2"
> plot(12) = gsn_csm_xy (wks,year,data_13,res) ; create plot
> print("4a   - Zone 14")
>
>   res at gsnRightString = "Zone 14" ; title
>   res at gsnLeftString  = "Avg.: "  +
> decimalPlaces(dim_avg_n(ALL_data_14,0)/1000000,1,True) + " t C m^-2"
> plot(13) = gsn_csm_xy (wks,year,data_14,res) ; create plot
> print("4a   - Zone 15")
>
>   res at gsnRightString = "Zone 15" ; title
>   res at gsnLeftString  = "Avg.: "  +
> decimalPlaces(dim_avg_n(ALL_data_15,0)/1000000,1,True) + " t C m^-2"
> plot(14) = gsn_csm_xy (wks,year,data_15,res) ; create plot
> print("4a   - Zone 16")
>
>   res at gsnRightString = "Zone 16" ; title
>   res at gsnLeftString  = "Avg.: "  +
> decimalPlaces(dim_avg_n(ALL_data_16,0)/1000000,1,True) + " t C m^-2"
> plot(15) = gsn_csm_xy (wks,year,data_16,res) ; create plot
>
> ;***********************************************
> ; CREATING A LEGEND
> ;***********************************************
>
> print("5 - Create legend")
>
>   gres             = True
>   gres at YPosPercent = 25    ; expressed as %, 0->100, sets position of top
> border of legend
>                            ;  when gres at Position is set to its default
> setting of "Top" (Default = 95.)
>   gres at XPosPercent = 50    ; expressed as %, 0->100, sets position of
> left border of legend(Default = 5.)
>   gres at vpHeightF   = 0.5   ; height of legend (NDC)
>   gres at vpWidth     = 1     ; height of legend (NDC)
>
>   lineres                   = True
>   lineres at lgAutoManage      = False
>   lineres at lgLineColors      =
> (/"blue","red","orange","black","green","pink","brown","purple","grey"/)
>   lineres at lgLineThicknesses = 10 ; line thicknesses
>   lineres at LineLengthPercent = 5. ; expressed as %, 0->100, length of line
>
>   textres                    = True
>   textres at lgAutoManage       = False
>   textres at lgLabels           = (/"C3 grassland","C3 shrubland","C4
> grassland","C4 shrubland","Other","Subtropical forest","Subtropical
> woodland","Temperate forest","Temperate woodland"/)  ; legend labels
> (required)
>   textres at lgLabelFontHeightF = .01   ; set the legend label font thickness
>   textres at vpHeightF          = 0.5   ; height of legend (NDC)
>   textres at vpWidthF           = 1     ; height of legend (NDC)
>
>   simple_legend_ndc(wks,gres,lineres,textres)
>
>
> /;
>   var_long_name_01 = (/"C3 grassland","C3 shrubland","C4 grassland","C4
> shrubland","Other"/)
>   var_long_name_02 = (/"Subtropical forest","Subtropical
> woodland","Temperate forest","Temperate woodland"/)
>
> ; line colors:
> "blue","red","orange","black","green","pink","brown","purple","grey"
>
> ; Legend elements 1-5
>   lgres                    = True
>   lgres at lgAutoManage       = True
>   lgres at lgLineColors       = (/"blue","red","orange","black","green"/)
>   lgres at lgLineThicknessF   = res at xyLineThicknesses  ; legend line
> thickness = contour line thickness
>   lgres at lgItemType         = "Lines"         ; show lines only (default)
>   lgres at lgItemCount        = 5 ; Number of items
>   lgres at lgLabelFontHeightF = .04             ; set the legend label font
> thickness
>   lgres at vpWidthF           = 1           ; width of legend (NDC)
>   lgres at vpHeightF          = 1             ; height of legend (NDC)
>   lgres at lgPerimColor       = "white"       ; draw the box perimeter in
> orange
>   lgres at lgPerimThicknessF  = 1.0             ; thicken the box perimeter
>   plot(16) = gsn_create_legend(wks,5,var_long_name_01,lgres)         ;
> create legend
>
>
> ; Legend elements 6-9
>   gres = True
>   gres at YPosPercent = 5. ; expressed as %, 0->100, sets position of top
> border of legend
> ; 0 = bottom of plot, 100 = top of plot
>   gres at XPosPercent = 50 ; expressed as %, 0->100, sets position of left
> border of legend
>   ; 0 = left side of plot
>
>   lgres                    = True
>   lgres at lgAutoManage       = False
>   lgres at lgLineColors       = (/"pink","brown","purple","grey"/)
>   lgres at lgLineThicknessF   = res at xyLineThicknesses  ; legend line
> thickness = 1/2 contour line thickness
>   lgres at lgItemType         = "Lines"         ; show lines only (default)
>   lgres at lgItemCount    = 4 ; Number of items
>   lgres at lgLabelFontHeightF = .04             ; set the legend label font
> thickness
>   lgres at vpWidthF           = 1           ; width of legend (NDC)
>   lgres at vpHeightF          = 1             ; height of legend (NDC)
>   lgres at lgPerimColor       = "white"       ; draw the box perimeter in
> orange
>   lgres at lgPerimThicknessF  = 1.0             ; thicken the box perimeter
>   plot(17) = gsn_create_legend(wks,gres,var_long_name_02,lgres)         ;
> create legend
>
> ; Legend elements 1-9
>   lgres                    = True
>   lgres at lgAutoManage    = False
>   lgres at lgLineColors       =
> (/"blue","red","orange","black","green","pink","brown","purple","grey"/)
>   lgres at lgLineThicknessF   = 5   ; legend line thickness
>   lgres at lgItemType         = "Lines"         ; show lines only (default)
>   lgres at lgItemCount        = 9 ; Number of items
>   lgres at lgLabelFontHeightF = .01             ; set the legend label font
> thickness
>   lgres at vpWidthF           = 0.5           ; width of legend (NDC)
>   lgres at vpHeightF          = 1             ; height of legend (NDC)
>   lgres at lgPerimColor       = "white"       ; draw the box perimeter in
> orange
>   lgres at lgPerimThicknessF  = 1.0             ; thicken the box perimeter
>   plot(16) =
> gsn_create_legend(wks,9,(/"C3-G","C3-S","C4-G","C4-S","Other","SF","SW","TF","TW"/),lgres)
>         ; create legend
> ;/
>
>
> ;***********************************************
> ; panel plots together
> ;***********************************************
>
> print("6 - Create plot matrix")
>
>   pres                 = True
>   pres at gsnMaximize     = False
>   pres at gsnPanelRowSpec = True
>   pres at gsnPanelCenter  = False
>   pres at gsnFrame        = False
>   pres at gsnPanelXWhiteSpacePercent = 10 ; horizontal white space between
> columns in percent
>   pres at gsnPanelYWhiteSpacePercent = 5 ; vertical white space between rows
> in percent
>   pres at gsnPanelMainString = RCP_title[h](0) + " | " + fs_title[i](0) + "
> | " + model_title[j](0) + " | NPP per func. group"
>   pres at tiMainFontHeightF  = 0.04
>   pres at tiMainFont         = 21
>   pres at gsnPanelXF  =
> (/-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1/)
>
>   gsn_panel(wks,plot,(/3,3,3,3,3,3/),pres)
>
>   frame(wks)
>
>   print("")
>
> print("**** DONE ****")
>
> delete([/diri,plot,diro,filo,wks,res,data_01,data_02,data_03,data_04,data_05,data_06,data_07,data_08,data_09,data_10,data_11,data_12,data_13,data_14,data_15,data_16,zone_01_f,zone_02_f,zone_03_f,zone_04_f,zone_05_f,zone_06_f,zone_07_f,zone_08_f,zone_09_f,zone_10_f,zone_11_f,zone_12_f,zone_13_f,zone_14_f,zone_15_f,zone_16_f,pres/])
> sleep(10)
>
> end do ; end model list loop
>
> end do ; end fs list loop
>
> end do ; end RCP list loop
>
> print("**** ALL DONE ****")
>
> end
>
>
>
>
> On Jul 30, 2018, at 12:18 PM, Adam Phillips <asphilli at ucar.edu> wrote:
>
> Hi Toni,
> The order should likely be something like this:
> res = True
> .....
> plot = new(16, graphic)
> do gg = 0,15
> plot(gg) = gsn_csm_xy(wks,...,res)
> end do
>
> panres = True  ; panel resource list
> panres at gsnFrame = False   ; do not flip the page after calling gsn_panel
> ...
> gsn_panel(wks,plot,(/6,3/),panres)
>
> gres = True
> gres at YPosPercent = 15.    ; expressed as %, 0->100, sets position of top
> border of legend
>                             ;  when gres at Position is set to its default
> setting of "Top" (Default = 95.)
> gres at XPosPercent = 35.      ; expressed as %, 0->100, sets position of
> left border of legend(Default = 5.
> lineres = True
> ...
> textres = True
> ....
> simple_legend_ndc(wks,gres,lineres,textres)
> frame(wks)   ; flip the page (/finish the plot)
>
> Note that I set the gres at YPosPercent = 15 which will mean the top of the
> legend will start at 15% of the way up the page, and gres at XPosPercent =
> 35 which will result in the legend starting 35% of the way over from the
> left side of the page. You will likely have to alter these settings a bit.
>
> Hope that helps. In the future, please include ncl-talk on all replies so
> that others in the future can see the issue resolution.
> Adam
>
>
> On Mon, Jul 30, 2018 at 11:09 AM Toni Klemm <toni-klemm at tamu.edu> wrote:
>
>> Hi Adam,
>>
>> That worked! It plotted the legend, and without any graph because I
>> commented that out. How do I get it to appear in my matrix plot, in the
>> bottom center? I attached that plot for reference. Originally I assigned
>> the legend "plot(16)" because plot 16 would be the bottom center. But
>> that’s when I got the error message. “plot” is an graphics array with 18
>> elements ("plot = new(18,graphic)”) Is that the problem?
>>
>> Thank you again,
>> Toni
>>
>>
>>
>> *Toni Klemm, Ph.D.*Postdoctoral Research Associate
>> Department of Ecosystem Science and Management
>> Texas A&M University, College Station, TX
>> Contributor at the Early Career Climate Forum
>> <https://urldefense.proofpoint.com/v2/url?u=http-3A__www.eccforum.org&d=DwMFaQ&c=ODFT-G5SujMiGrKuoJJjVg&r=WsLJ5ywbW3XnTzqo_ETV62H6s1a5bcGgnrpl7xPRfic&m=vZDXoNZVh-FHQeBimjUETu1oZnRy5LXMitrIB6z2EeY&s=uuJLFqTkjxdif_aJ0nFmcD7xTUrwa7ywQvg4LInDJmM&e=>
>> www.toni-klemm.de
>> <https://urldefense.proofpoint.com/v2/url?u=http-3A__www.toni-2Dklemm.de&d=DwMFaQ&c=ODFT-G5SujMiGrKuoJJjVg&r=WsLJ5ywbW3XnTzqo_ETV62H6s1a5bcGgnrpl7xPRfic&m=vZDXoNZVh-FHQeBimjUETu1oZnRy5LXMitrIB6z2EeY&s=U0Y5rnows5YR473sgGxk8P53CHZkxTXOzoMSI46sPgI&e=>
>>  | @toniklemm
>> <https://urldefense.proofpoint.com/v2/url?u=http-3A__twitter.com_toniklemm&d=DwMFaQ&c=ODFT-G5SujMiGrKuoJJjVg&r=WsLJ5ywbW3XnTzqo_ETV62H6s1a5bcGgnrpl7xPRfic&m=vZDXoNZVh-FHQeBimjUETu1oZnRy5LXMitrIB6z2EeY&s=aWwtxR_l1qBEhQb4TrnxEXWIOddjAahWNAUxcVHnUgo&e=>
>>
>>
>>
>>
>> On Jul 30, 2018, at 11:52 AM, Adam Phillips <asphilli at ucar.edu> wrote:
>>
>> Hi Toni,
>> I think you're loading it correctly. Note though that simple_legend_ndc
>> is a procedure, so nothing is returned from the procedure to the calling
>> script.
>> Try changing this:
>> plot(16) = simple_legend_ndc(wks,gres,lineres,textres)
>> to this:
>> simple_legend_ndc(wks,gres,lineres,textres)
>>
>> Adam
>>
>> On Mon, Jul 30, 2018 at 10:46 AM Toni Klemm <toni-klemm at tamu.edu> wrote:
>>
>>> Hi Alex, thanks again!
>>>
>>> Unfortunately I’m still getting the error. I saved the function to my
>>> server space and loaded it at the beginning of the script like this:
>>>
>>> load "~/NIFA/NCL_6.5.0_functions/simple_legend_ndc.ncl”
>>>
>>> The command to execute it in the script looks like this (I used gres,
>>> lineres, and textres from the example to test it):
>>>
>>> plot(16) = simple_legend_ndc(wks,gres,lineres,textres)
>>>
>>> I also tried this:
>>>
>>> plot(16) = simple_legend_ndc.ncl(wks,gres,lineres,textres)
>>>
>>> but got the same error.
>>>
>>> This is the error I’m getting:
>>>
>>> fatal:syntax error: line 510 in file
>>> matrix_chart_NPP_percentage_all_zones_all_groups.ncl before or near
>>> simple_legend_ndc
>>>   plot(16) = simple_legend_ndc
>>> -----------------------------^
>>>
>>> Am I loading the function correctly? I’m not getting an error about it,
>>> so I assume it is loading correctly.
>>>
>>> Thanks again,
>>> Toni
>>>
>>>
>>>
>>> *Toni Klemm, Ph.D.*Postdoctoral Research Associate
>>> Department of Ecosystem Science and Management
>>> Texas A&M University, College Station, TX
>>> Contributor at the Early Career Climate Forum
>>> <https://urldefense.proofpoint.com/v2/url?u=http-3A__www.eccforum.org&d=DwMFaQ&c=ODFT-G5SujMiGrKuoJJjVg&r=WsLJ5ywbW3XnTzqo_ETV62H6s1a5bcGgnrpl7xPRfic&m=OCrz0F80P765WcmE1_9SOXWuUkltz4e82DSP0ufoLI4&s=C2brqs0P8JS044Qhu-m82ayNzyBbc2MpmxfprvHLvoc&e=>
>>> www.toni-klemm.de
>>> <https://urldefense.proofpoint.com/v2/url?u=http-3A__www.toni-2Dklemm.de&d=DwMFaQ&c=ODFT-G5SujMiGrKuoJJjVg&r=WsLJ5ywbW3XnTzqo_ETV62H6s1a5bcGgnrpl7xPRfic&m=OCrz0F80P765WcmE1_9SOXWuUkltz4e82DSP0ufoLI4&s=TYOC59ftTJQY1ImeUty7VwI_9hWYG7ERiUNyzAAKcts&e=>
>>>  | @toniklemm
>>> <https://urldefense.proofpoint.com/v2/url?u=http-3A__twitter.com_toniklemm&d=DwMFaQ&c=ODFT-G5SujMiGrKuoJJjVg&r=WsLJ5ywbW3XnTzqo_ETV62H6s1a5bcGgnrpl7xPRfic&m=OCrz0F80P765WcmE1_9SOXWuUkltz4e82DSP0ufoLI4&s=zQ1pM6aCfNyE08W1HkO8qwH86INpW5B6TBlVk7EJGV0&e=>
>>>
>>> <
>>>
>>

-- 
Adam Phillips
Associate Scientist,  Climate and Global Dynamics Laboratory, NCAR
www.cgd.ucar.edu/staff/asphilli/   303-497-1726

<http://www.cgd.ucar.edu/staff/asphilli>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20180730/24a7efd6/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screen Shot 2018-07-30 at 1.45.15 PM.png
Type: image/png
Size: 527920 bytes
Desc: not available
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20180730/24a7efd6/attachment-0002.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screen Shot 2018-07-30 at 1.45.15 PM.png
Type: image/png
Size: 527920 bytes
Desc: not available
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20180730/24a7efd6/attachment-0003.png>


More information about the ncl-talk mailing list