<div dir="ltr">Hi Giorgio,<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><br></div><div>begin<br> f = addfile ("$NCARG_ROOT/lib/ncarg/data/cdf/<a 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><br></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><br></div><div>Hope that helps!</div><div>Adam</div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Apr 17, 2023 at 10:27 AM Giorgio Graffino via ncl-talk <<a href="mailto:ncl-talk@mailman.ucar.edu">ncl-talk@mailman.ucar.edu</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><p><span style="font-family:Arial;font-size:12pt">[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 href="https://www.ncl.ucar.edu/Applications/Scripts/tm_12.ncl" target="_blank">https://www.ncl.ucar.edu/Applications/Scripts/tm_12.ncl</a><br>; and <a href="https://www.ncl.ucar.edu/Applications/Scripts/panel_GWLs_Rain.ncl" target="_blank">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">ncl-talk@mailman.ucar.edu</a><br>A: <a href="mailto:ncl-talk@ucar.edu" target="_blank">ncl-talk@ucar.edu</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:12pt">Hello NCLers,</span></p><p> </p><p><span style="font-family:Arial;font-size:12pt">I need to draw tickmark labels with two different colors (red and blue). The script is quite complex; it uses part of <a href="https://www.ncl.ucar.edu/Applications/Scripts/table_8.ncl" target="_blank">https://www.ncl.ucar.edu/Applications/Scripts/table_8.ncl</a> 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:12pt">I tried to generate colored labels in another way. I found this example (<a href="https://www.ncl.ucar.edu/Applications/Scripts/tm_12.ncl" target="_blank">https://www.ncl.ucar.edu/Applications/Scripts/tm_12.ncl</a>), 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:12pt">I found out that there is an unadvertised gsnPanelSave resource used in <a href="https://www.ncl.ucar.edu/Applications/Scripts/panel_GWLs_Rain.ncl" target="_blank">https://www.ncl.ucar.edu/Applications/Scripts/panel_GWLs_Rain.ncl</a> 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:12pt">Cheers,</span></p><p><span style="font-family:Arial;font-size:12pt">Giorgio</span></p><p> </p><p><span style="font-family:Arial;font-size:12pt">;----------------------------------------------------------------------</span><br><span style="font-family:Arial;font-size:12pt">; This procedure replaces a plot's X/Y tickmark labels with custom</span><br><span style="font-family:Arial;font-size:12pt">; labels created by drawing individual text strings </span><br><span style="font-family:Arial;font-size:12pt">; (adapted from <a href="https://www.ncl.ucar.edu/Applications/Scripts/tm_12.ncl" target="_blank">https://www.ncl.ucar.edu/Applications/Scripts/tm_12.ncl</a>)</span><br><span style="font-family:Arial;font-size:12pt">;----------------------------------------------------------------------</span><br><span style="font-family:Arial;font-size:12pt">procedure replace_tickmark_labels(wks,plot)</span><br><span style="font-family:Arial;font-size:12pt">local txres, xlabels, ylabels, xmin, ymin, xfonth, yfonth</span><br><span style="font-family:Arial;font-size:12pt">begin</span><br><span style="font-family:Arial;font-size:12pt">;---Turn off plot's X and Y tickmark labels</span><br><span style="font-family:Arial;font-size:12pt"> setvalues plot</span><br><span style="font-family:Arial;font-size:12pt"> "tmXBLabelsOn" : False</span><br><span style="font-family:Arial;font-size:12pt"> "tmYLLabelsOn" : False</span><br><span style="font-family:Arial;font-size:12pt"> end setvalues</span><br><span style="font-family:Arial;font-size:12pt"> </span><br><span style="font-family:Arial;font-size:12pt">;---Retrieve some values so we can reconstruct the labels</span><br><span style="font-family:Arial;font-size:12pt"> getvalues plot</span><br><span style="font-family:Arial;font-size:12pt"> "tmXBLabels" : xlabels</span><br><span style="font-family:Arial;font-size:12pt"> "tmYLLabels" : ylabels</span><br><span style="font-family:Arial;font-size:12pt"> "tmXBValues" : xvalues</span><br><span style="font-family:Arial;font-size:12pt"> "tmYLValues" : yvalues</span><br><span style="font-family:Arial;font-size:12pt"> "trXMinF" : xmin</span><br><span style="font-family:Arial;font-size:12pt"> "trYMinF" : ymin</span><br><span style="font-family:Arial;font-size:12pt"> "tmYLMajorOutwardLengthF" : ylength</span><br><span style="font-family:Arial;font-size:12pt"> "tmXBMajorOutwardLengthF" : xlength</span><br><span style="font-family:Arial;font-size:12pt"> "tmXBLabelFontHeightF" : xfont_height</span><br><span style="font-family:Arial;font-size:12pt"> "tmYLLabelFontHeightF" : yfont_height</span><br><span style="font-family:Arial;font-size:12pt"> end getvalues</span></p><p><span style="font-family:Arial;font-size:12pt">;---Get the NDC locations for the new tickmark labels</span><br><span style="font-family:Arial;font-size:12pt"> xvalues_ndc = new(dimsizes(xvalues),float)</span><br><span style="font-family:Arial;font-size:12pt"> yvalues_ndc = new(dimsizes(yvalues),float)</span><br><span style="font-family:Arial;font-size:12pt"> xmin_ndc = new(1,float)</span><br><span style="font-family:Arial;font-size:12pt"> ymin_ndc = new(1,float)</span><br><span style="font-family:Arial;font-size:12pt"> datatondc(plot,xvalues,yvalues,xvalues_ndc,yvalues_ndc)</span><br><span style="font-family:Arial;font-size:12pt"> datatondc(plot,xmin,ymin,xmin_ndc,ymin_ndc)</span></p><p><span style="font-family:Arial;font-size:12pt">;---Make sure the tickmark labels don't touch the tickmarks.</span><br><span style="font-family:Arial;font-size:12pt"> xmin_ndc = xmin_ndc-(1.8*ylength) </span><br><span style="font-family:Arial;font-size:12pt"> ymin_ndc = ymin_ndc-(1.8*xlength)</span><br><span style="font-family:Arial;font-size:12pt"> </span><br><span style="font-family:Arial;font-size:12pt">;---Color the first four labels red</span><br><span style="font-family:Arial;font-size:12pt"> txres = True</span><br><span style="font-family:Arial;font-size:12pt"> txres@txFontColor = "Red"</span></p><p><span style="font-family:Arial;font-size:12pt">;---Draw the first four labels</span><br><span style="font-family:Arial;font-size:12pt"> txres@txFontHeightF = xfont_height</span><br><span style="font-family:Arial;font-size:12pt"> gsn_text_ndc(wks,ylabels(0:3),xmin_ndc,yvalues_ndc(0:3),txres)</span><br><span style="font-family:Arial;font-size:12pt"> txres@txFontHeightF = yfont_height</span><br><span style="font-family:Arial;font-size:12pt"> gsn_text_ndc(wks,xlabels(0:3),xvalues_ndc(0:3),ymin_ndc,txres)</span></p><p><span style="font-family:Arial;font-size:12pt">;---Color the last four labels blue</span><br><span style="font-family:Arial;font-size:12pt"> txres@txFontColor = "Blue"</span></p><p><span style="font-family:Arial;font-size:12pt">;---Draw the last four labels</span><br><span style="font-family:Arial;font-size:12pt"> txres@txFontHeightF = xfont_height</span><br><span style="font-family:Arial;font-size:12pt"> gsn_text_ndc(wks,ylabels(4:7),xmin_ndc,yvalues_ndc(4:7),txres)</span><br><span style="font-family:Arial;font-size:12pt"> txres@txFontHeightF = yfont_height</span><br><span style="font-family:Arial;font-size:12pt"> gsn_text_ndc(wks,xlabels(4:7),xvalues_ndc(4:7),ymin_ndc,txres)</span></p><p><span style="font-family:Arial;font-size:12pt">end</span><br> </p><hr><p>_______________________________________________<br>ncl-talk mailing list<br><span><a href="mailto:ncl-talk@mailman.ucar.edu" target="_blank">ncl-talk@mailman.ucar.edu</a></span><br>List instructions, subscriber options, unsubscribe:<br><a rel="noopener noreferrer" href="https://mailman.ucar.edu/mailman/listinfo/ncl-talk" target="_blank">https://mailman.ucar.edu/mailman/listinfo/ncl-talk</a><br> </p></blockquote>_______________________________________________<br>
ncl-talk mailing list<br>
<a href="mailto:ncl-talk@mailman.ucar.edu" target="_blank">ncl-talk@mailman.ucar.edu</a><br>
List instructions, subscriber options, unsubscribe:<br>
<a href="https://mailman.ucar.edu/mailman/listinfo/ncl-talk" rel="noreferrer" target="_blank">https://mailman.ucar.edu/mailman/listinfo/ncl-talk</a><br>
</blockquote></div><br clear="all"><div><br></div><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div><div><span><font color="#888888">Adam Phillips <br></font></span></div><span><font color="#888888">Associate Scientist IV, Climate Analysis Section</font></span></div><div><span><font color="#888888">Climate and Global Dynamics Laboratory<br></font></span></div></div><div><span style="color:rgb(136,136,136)">National Center for Atmospheric Research</span><span><font color="#888888"><br></font></span></div><div><span><font color="#888888"><a href="http://www.cgd.ucar.edu/staff/asphilli/" target="_blank">www.cgd.ucar.edu/staff/asphilli/</a> </font></span></div><span><font color="#888888"></font></span><div><div><span><font color="#888888"><br></font></span><div><span><font color="#888888"><a href="http://www.cgd.ucar.edu/staff/asphilli" target="_blank"></a></font></span></div></div></div></div></div></div></div></div></div></div></div>