<p><span style="font-family:Arial;font-size:12pt;">Thanks Adam, </span><br><br><span style="font-family:Arial;font-size:12pt;">I don't understand why, but it worked! I managed to add colored labels on a panel table plot.</span></p><p> </p><p><span style="font-family:Arial;font-size:12pt;">Cheers,</span></p><p><span style="font-family:Arial;font-size:12pt;">Giorgio</span><br><br> </p><blockquote><p>------ Messaggio Originale ------<br>Da: asphilli@ucar.edu<br>A: g.graffino@tim.it Cc: ncl-talk@ucar.edu<br>Inviato: mercoledì 19 aprile 2023 00:12<br>Oggetto: Re: [ncl-talk] How to use plot tickmark labels with different colors<br> </p><div dir="ltr"><p>Hi Giorgio,</p><div>You could try setting tmXBLabelFontColor to a RGBA value, setting the A value to 0. Using xy example #1 as a template:</div><div> </div><div>begin<br> f     = addfile ("$NCARG_ROOT/lib/ncarg/data/cdf/<a target="_blank" rel="noopener noreferrer" href="http://uv300.nc">uv300.nc</a>","r")<br> u     = f->U                                    ; get u data<br><br> wks   = gsn_open_wks ("png","xy")               ; send graphics to PNG file<br> res                  = True                     ; plot mods desired<br> res@gsnFrame = False<br> res@tiMainString     = "Basic XY plot"          ; add title<br> res@tmXBLabelFontColor = (/0,0,1,0./).   ; <------ Set to blue, but make the color completely transparent.<br> plot  = gsn_csm_xy (wks,u&lat,u(0,:,{82}),res) ; create plot<br> res@tmXBLabelFontColor = (/0,1,.05,1./).   ; <---- Set to green, but make the color opaque. <br> plot2  = gsn_csm_xy (wks,u&lat,u(0,:,{82}),res) ; create plot<br> frame(wks)<br>end<br> </div><div> </div><div>If you run the above script you will see clean green X-axis labels (without any weird blue outlines to the green labels).</div><div> </div><div>Hope that helps!</div><div>Adam</div><div> </div></div><p><br> </p><div class="gmail_quote"><div class="gmail_attr" dir="ltr">On Mon, Apr 17, 2023 at 10:27 AM Giorgio Graffino via ncl-talk <<a href="mailto:ncl-talk@mailman.ucar.edu"><span class="wt_Email">ncl-talk@mailman.ucar.edu</span></a>> wrote:<br> </div><blockquote class="gmail_quote" style="border-left:1.0px solid rgb(204,204,204);margin:0.0px 0.0px 0.0px 0.8ex;padding-left:1.0ex;"><p><span style="font-family:Arial;font-size:12.0pt;">[UPDATE]</span><br><br>I made some progress using gsnPanelSave adapting replace_tickmark_labels and calling it after gsn_panel. To make the individual plots of the size I want, I'm drawing some "invisible" labels using res@tmXBLabelFontColor = "Background", then I'm redrawing them as red or blue. As you can see, the result is not great. </p><p> </p><p>If I set res@tmXBLabelFontColor = "Transparent" the script doesn't work. Is there a way to draw transparent labels?  Or is there another way to do what I'm trying to do (see email below)?<br><br>Cheers,</p><p>Giorgio</p><p> </p><p>;----------------------------------------------------------------------<br>; This procedure draw X/Y tickmark labels with custom<br>; labels created by drawing individual text strings read via gsnPanelSave<br>; (adapted from <a target="_blank" rel="noopener noreferrer" href="https://www.ncl.ucar.edu/Applications/Scripts/tm_12.ncl">https://www.ncl.ucar.edu/Applications/Scripts/tm_12.ncl</a><br>; and <a target="_blank" rel="noopener noreferrer" href="https://www.ncl.ucar.edu/Applications/Scripts/panel_GWLs_Rain.ncl">https://www.ncl.ucar.edu/Applications/Scripts/panel_GWLs_Rain.ncl</a>)<br>;----------------------------------------------------------------------<br>procedure replace_tickmark_labels_panel(wks,plot)<br>local txres, xlabels, ylabels, xmin, ymin, xfonth, yfonth, xangle, xjust<br>begin<br>;---Retrieve some values so we can reconstruct the labels<br> getvalues plot<br>   "tmXBLabels"              : xlabels<br>   "tmYLLabels"              : ylabels<br>   "tmXBValues"              : xvalues<br>   "tmYLValues"              : yvalues<br>   "trXMinF"                 : xmin<br>   "trYMinF"                 : ymin<br>   "tmYLMajorOutwardLengthF" : ylength<br>   "tmXBMajorOutwardLengthF" : xlength<br>   "tmXBLabelFontHeightF"    : xfont_height<br>   "tmYLLabelFontHeightF"    : yfont_height<br>   "tmXBLabelAngleF"         : xangle<br>   "tmXBLabelJust"           : xjust<br> end getvalues</p><p>;---Get the NDC locations for the new tickmark labels<br> xvalues_ndc = new(dimsizes(xvalues),float)<br> yvalues_ndc = new(dimsizes(yvalues),float)<br> xmin_ndc    = new(1,float)<br> ymin_ndc    = new(1,float)<br> datatondc(plot,xvalues,yvalues,xvalues_ndc,yvalues_ndc)<br> datatondc(plot,xmin,ymin,xmin_ndc,ymin_ndc)</p><p>;---Make sure the plot doesn't overlay with the tickmark labels.<br> xmin_ndc = xmin_ndc-0.0075<br> ymin_ndc = ymin_ndc-0.0075<br> <br>;---Color the first four labels red<br> txres = True<br> txres@txJust = xjust<br> txres@txFontColor = "Red"</p><p>;---Draw the first four labels<br> txres@txFontHeightF         = xfont_height<br> gsn_text_ndc(wks,ylabels(0:3),xmin_ndc,yvalues_ndc(0:3),txres)<br> txres@txAngleF = xangle<br> txres@txFontHeightF         = yfont_height<br> gsn_text_ndc(wks,xlabels(0:3),xvalues_ndc(0:3),ymin_ndc,txres)</p><p>;---Color the last four labels blue<br> txres@txFontColor = "Blue"</p><p>;---Draw the last four labels<br> txres@txAngleF = 0.<br> txres@txFontHeightF         = xfont_height<br> gsn_text_ndc(wks,ylabels(4:7),xmin_ndc,yvalues_ndc(4:7),txres)<br> txres@txAngleF = xangle<br> txres@txFontHeightF         = yfont_height<br> gsn_text_ndc(wks,xlabels(4:7),xvalues_ndc(4:7),ymin_ndc,txres)<br>end<br> </p><p> </p><blockquote><p>------ Messaggio Originale ------<br>Da: <a href="mailto:ncl-talk@mailman.ucar.edu" target="_blank"><span class="wt_Email">ncl-talk@mailman.ucar.edu</span></a><br>A: <a href="mailto:ncl-talk@ucar.edu" target="_blank"><span class="wt_Email">ncl-talk@ucar.edu</span></a><br>Inviato: venerdì 14 aprile 2023 17:10<br>Oggetto: [ncl-talk] How to use plot tickmark labels with different colors<br> </p><p><span style="font-family:Arial;font-size:12.0pt;">Hello NCLers,</span></p><p> </p><p><span style="font-family:Arial;font-size:12.0pt;">I need to draw tickmark labels with two different colors (red and blue). The script is quite complex; it uses part of </span><a target="_blank" rel="noopener noreferrer" href="https://www.ncl.ucar.edu/Applications/Scripts/table_8.ncl"><span style="font-family:Arial;font-size:12.0pt;">https://www.ncl.ucar.edu/Applications/Scripts/table_8.ncl</span></a><span style="font-family:Arial;font-size:12.0pt;"> to draw many table plots, which become part of a panel plot (see attached HadCM3_plot_maps_cor_3.png). I can't find a resource like tmXBLabelFontColors, or something able to handle an array of colors like xyLineColors does for lines. Does anyone know if such resource exist?</span></p><p> </p><p><span style="font-family:Arial;font-size:12.0pt;">I tried to generate colored labels in another way. I found this example (</span><a target="_blank" rel="noopener noreferrer" href="https://www.ncl.ucar.edu/Applications/Scripts/tm_12.ncl"><span style="font-family:Arial;font-size:12.0pt;">https://www.ncl.ucar.edu/Applications/Scripts/tm_12.ncl</span></a><span style="font-family:Arial;font-size:12.0pt;">), containing a procedure able to remove labels from a plot and redraw them. My version of the procedure is pasted below; it reads the value and the location of the labels from the plot function, and draws them again using gsn_text_ndc. I included the procedure in my script but the result is not the intended one (see attached HadCM3_plot_maps_cor_3colored.png).</span></p><p> </p><p><span style="font-family:Arial;font-size:12.0pt;">I found out that there is an unadvertised gsnPanelSave resource used in </span><a target="_blank" rel="noopener noreferrer" href="https://www.ncl.ucar.edu/Applications/Scripts/panel_GWLs_Rain.ncl"><span style="font-family:Arial;font-size:12.0pt;">https://www.ncl.ucar.edu/Applications/Scripts/panel_GWLs_Rain.ncl</span></a><span style="font-family:Arial;font-size:12.0pt;"> to to keep the plots in their resized state. I think it might help. Can anyone please tell me how it works?</span></p><p> </p><p><span style="font-family:Arial;font-size:12.0pt;">Cheers,</span></p><p><span style="font-family:Arial;font-size:12.0pt;">Giorgio</span></p><p> </p><p><span style="font-family:Arial;font-size:12.0pt;">;----------------------------------------------------------------------</span><br><span style="font-family:Arial;font-size:12.0pt;">; This procedure replaces a plot's X/Y tickmark labels with custom</span><br><span style="font-family:Arial;font-size:12.0pt;">; labels created by drawing individual text strings </span><br><span style="font-family:Arial;font-size:12.0pt;">; (adapted from </span><a target="_blank" rel="noopener noreferrer" href="https://www.ncl.ucar.edu/Applications/Scripts/tm_12.ncl"><span style="font-family:Arial;font-size:12.0pt;">https://www.ncl.ucar.edu/Applications/Scripts/tm_12.ncl</span></a><span style="font-family:Arial;font-size:12.0pt;">)</span><br><span style="font-family:Arial;font-size:12.0pt;">;----------------------------------------------------------------------</span><br><span style="font-family:Arial;font-size:12.0pt;">procedure replace_tickmark_labels(wks,plot)</span><br><span style="font-family:Arial;font-size:12.0pt;">local txres, xlabels, ylabels, xmin, ymin, xfonth, yfonth</span><br><span style="font-family:Arial;font-size:12.0pt;">begin</span><br><span style="font-family:Arial;font-size:12.0pt;">;---Turn off plot's X and Y tickmark labels</span><br><span style="font-family:Arial;font-size:12.0pt;"> setvalues plot</span><br><span style="font-family:Arial;font-size:12.0pt;">   "tmXBLabelsOn"  : False</span><br><span style="font-family:Arial;font-size:12.0pt;">   "tmYLLabelsOn"  : False</span><br><span style="font-family:Arial;font-size:12.0pt;"> end setvalues</span><br><span style="font-family:Arial;font-size:12.0pt;">   </span><br><span style="font-family:Arial;font-size:12.0pt;">;---Retrieve some values so we can reconstruct the labels</span><br><span style="font-family:Arial;font-size:12.0pt;"> getvalues plot</span><br><span style="font-family:Arial;font-size:12.0pt;">   "tmXBLabels"              : xlabels</span><br><span style="font-family:Arial;font-size:12.0pt;">   "tmYLLabels"              : ylabels</span><br><span style="font-family:Arial;font-size:12.0pt;">   "tmXBValues"              : xvalues</span><br><span style="font-family:Arial;font-size:12.0pt;">   "tmYLValues"              : yvalues</span><br><span style="font-family:Arial;font-size:12.0pt;">   "trXMinF"                 : xmin</span><br><span style="font-family:Arial;font-size:12.0pt;">   "trYMinF"                 : ymin</span><br><span style="font-family:Arial;font-size:12.0pt;">   "tmYLMajorOutwardLengthF" : ylength</span><br><span style="font-family:Arial;font-size:12.0pt;">   "tmXBMajorOutwardLengthF" : xlength</span><br><span style="font-family:Arial;font-size:12.0pt;">   "tmXBLabelFontHeightF"    : xfont_height</span><br><span style="font-family:Arial;font-size:12.0pt;">   "tmYLLabelFontHeightF"    : yfont_height</span><br><span style="font-family:Arial;font-size:12.0pt;"> end getvalues</span></p><p><span style="font-family:Arial;font-size:12.0pt;">;---Get the NDC locations for the new tickmark labels</span><br><span style="font-family:Arial;font-size:12.0pt;"> xvalues_ndc = new(dimsizes(xvalues),float)</span><br><span style="font-family:Arial;font-size:12.0pt;"> yvalues_ndc = new(dimsizes(yvalues),float)</span><br><span style="font-family:Arial;font-size:12.0pt;"> xmin_ndc    = new(1,float)</span><br><span style="font-family:Arial;font-size:12.0pt;"> ymin_ndc    = new(1,float)</span><br><span style="font-family:Arial;font-size:12.0pt;"> datatondc(plot,xvalues,yvalues,xvalues_ndc,yvalues_ndc)</span><br><span style="font-family:Arial;font-size:12.0pt;"> datatondc(plot,xmin,ymin,xmin_ndc,ymin_ndc)</span></p><p><span style="font-family:Arial;font-size:12.0pt;">;---Make sure the tickmark labels don't touch the tickmarks.</span><br><span style="font-family:Arial;font-size:12.0pt;"> xmin_ndc = xmin_ndc-(1.8*ylength)     </span><br><span style="font-family:Arial;font-size:12.0pt;"> ymin_ndc = ymin_ndc-(1.8*xlength)</span><br><span style="font-family:Arial;font-size:12.0pt;"> </span><br><span style="font-family:Arial;font-size:12.0pt;">;---Color the first four labels red</span><br><span style="font-family:Arial;font-size:12.0pt;"> txres = True</span><br><span style="font-family:Arial;font-size:12.0pt;"> txres@txFontColor = "Red"</span></p><p><span style="font-family:Arial;font-size:12.0pt;">;---Draw the first four labels</span><br><span style="font-family:Arial;font-size:12.0pt;"> txres@txFontHeightF         = xfont_height</span><br><span style="font-family:Arial;font-size:12.0pt;"> gsn_text_ndc(wks,ylabels(0:3),xmin_ndc,yvalues_ndc(0:3),txres)</span><br><span style="font-family:Arial;font-size:12.0pt;"> txres@txFontHeightF         = yfont_height</span><br><span style="font-family:Arial;font-size:12.0pt;"> gsn_text_ndc(wks,xlabels(0:3),xvalues_ndc(0:3),ymin_ndc,txres)</span></p><p><span style="font-family:Arial;font-size:12.0pt;">;---Color the last four labels blue</span><br><span style="font-family:Arial;font-size:12.0pt;"> txres@txFontColor = "Blue"</span></p><p><span style="font-family:Arial;font-size:12.0pt;">;---Draw the last four labels</span><br><span style="font-family:Arial;font-size:12.0pt;"> txres@txFontHeightF         = xfont_height</span><br><span style="font-family:Arial;font-size:12.0pt;"> gsn_text_ndc(wks,ylabels(4:7),xmin_ndc,yvalues_ndc(4:7),txres)</span><br><span style="font-family:Arial;font-size:12.0pt;"> txres@txFontHeightF         = yfont_height</span><br><span style="font-family:Arial;font-size:12.0pt;"> gsn_text_ndc(wks,xlabels(4:7),xvalues_ndc(4:7),ymin_ndc,txres)</span></p><p><span style="font-family:Arial;font-size:12.0pt;">end</span><br> </p><hr><p>_______________________________________________<br>ncl-talk mailing list<br><a href="mailto:ncl-talk@mailman.ucar.edu" target="_blank"><span class="wt_Email">ncl-talk@mailman.ucar.edu</span></a><br>List instructions, subscriber options, unsubscribe:<br><a target="_blank" rel="noopener noreferrer" href="https://mailman.ucar.edu/mailman/listinfo/ncl-talk">https://mailman.ucar.edu/mailman/listinfo/ncl-talk</a><br> </p></blockquote><p>_______________________________________________<br>ncl-talk mailing list<br><a href="mailto:ncl-talk@mailman.ucar.edu" target="_blank"><span class="wt_Email">ncl-talk@mailman.ucar.edu</span></a><br>List instructions, subscriber options, unsubscribe:<br><a target="_blank" rel="noopener noreferrer" href="https://mailman.ucar.edu/mailman/listinfo/ncl-talk">https://mailman.ucar.edu/mailman/listinfo/ncl-talk</a><br> </p></blockquote></div><p><br> </p><div> </div><p><span class="gmail_signature_prefix">-- </span><br> </p><div class="gmail_signature" dir="ltr"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div><div><span style="color:#888888;"><span>Adam Phillips </span></span><br> </div><p><span style="color:#888888;"><span>Associate Scientist IV, Climate Analysis Section</span></span></p></div><div><span style="color:#888888;"><span>Climate and Global Dynamics Laboratory</span></span><br> </div></div><div><span style="color:rgb(136,136,136);">National Center for Atmospheric Research</span><br> </div><div><a target="_blank" rel="noopener noreferrer" href="http://www.cgd.ucar.edu/staff/asphilli/"><span style="color:#888888;"><span>www.cgd.ucar.edu/staff/asphilli/</span></span></a><span style="color:#888888;"><span> </span></span></div><div><div><p><br> </p><div> </div></div></div></div></div></div></div></div></div></div></div></blockquote>