<div dir="ltr">Hi Jason,<div><a href="http://www.ncl.ucar.edu/Document/Graphics/Interfaces/gsn_add_text.shtml">gsn_add_text</a> is a function, so you need to pass the returned output to a variable. Assuming a value of 70 is within the x-axis range of the plot, and 5.6 is within the y-axis range, you should be good to go with something like this: </div><div>dum = gsn_add_text(wks,plt,text, 70, 5.6,txres)</div><div>Hope that helps!</div><div>Adam</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Oct 23, 2020 at 1:20 PM Herb, Jason 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">
<div dir="ltr">
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
Hello all,</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
I am attempting to print the linear regression equation mX+b on my XY scatter plots. Unfortunatly, I have not had much luck in getting it to plot. Code script is below. Any suggestions?</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
Thankyou<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
;This will create scatterplots of Modis derived PM2.5 data and surface measured PM2.5 data.
<div><br>
</div>
<div>begin</div>
<div>f = "QNC-XY.out"</div>
<div>data = asciiread(f,(/5856,2/),"float")</div>
<div>x = data(:,1)</div>
<div>; x = new((/2,366/),float)</div>
<div> x@_FillValue=integertoshort(-999)</div>
<div> x=where(x.lt.0,x@_FillValue,x)</div>
<div>x@long_name = "PSP PM25"</div>
<div>; x(0,:) = data(:,4)</div>
<div> y = data(:,0) </div>
<div>y@long_name = "Modis Derived PM25"</div>
<div> y@_FillValue=integertoshort(-999)</div>
<div> y=where(y.lt.0,y@_FillValue,y)</div>
<div><br>
</div>
<div>;************************************************</div>
<div>; calculate the regression coefficient (slope) </div>
<div>;************************************************</div>
<div> rcl = regline(x, y) ; slope </div>
<div> rcl@units = "MODIS/PSP" </div>
<div> print(rcl)</div>
<div><br>
</div>
<div> rcl_anova = regline_stats(x,y) ; linear regression: ANOVA</div>
<div> print(rcl_anova)</div>
<div><br>
</div>
<div>;************************************************</div>
<div>; create an array to hold both the original data</div>
<div>; and the calculated regression line </div>
<div>; ---------</div>
<div>; y = mx+b </div>
<div>; m is the slope: rc returned from regline</div>
<div>; b is the y intercept: rc@yave attribute of rc returned from regline</div>
<div>;************************************************</div>
<div>; pltarry := new ( (/2,366/), typeof(x), x@_FillValue)</div>
<div> pltarry := new ( (/2,5856/), typeof(x), x@_FillValue)</div>
<div>;************************************************************</div>
<div> print(sprintf("%4.0f", x)+" "+sprintf("%4.0f", y))</div>
<div><br>
</div>
<div> pltarry(0,:) = y ; use markers</div>
<div>; pltarry(1,:) = rcl*x + rcl@yintercept ; use solid line</div>
<div> pltarry(1,:) = rcl*(x-rcl@xave) + rcl@yave ; y =m*x + B</div>
<div><br>
</div>
<div>;************************************************</div>
<div>; Plotting parameters</div>
<div>;************************************************</div>
<div> plot = new (1, "graphic")</div>
<div> wks = gsn_open_wks("png","scatter_regress") ; send graphics to PNG file</div>
<div><br>
</div>
<div> resP = True ; modify the panel plot</div>
<div> resP@gsnMaximize = True ; maximize plot in frame</div>
<div> resP@gsnPanelMainString = "Modis vs PSP" ; title</div>
<div> resP@gsnPanelRowSpec = True ; tell panel what order to plot</div>
<div>; gsn_panel(wks,plot,(/2,1/),resP)</div>
<div><br>
</div>
<div><br>
</div>
<div>; wks = gsn_open_wks("png","scatter_regress") ; send graphics to PNG file</div>
<div> res = True</div>
<div> res@gsnDraw = False</div>
<div> res@gsnFrame = False</div>
<div> res@xyMarkLineModes = (/"Markers","Lines"/) ; choose which have markers</div>
<div> res@xyMarkers = 16 ; choose type of marker </div>
<div> res@xyMarkerColor = "red" ; Marker color</div>
<div> res@xyMarkerSizeF = 0.005 ; Marker size (default 0.01)</div>
<div> res@xyDashPatterns = 1 ; solid line </div>
<div> res@xyLineThicknesses = (/1,2/) ; set second line to 2</div>
<div> res@tmYLFormat = "f" ; not necessary but nicer labels
</div>
<div><br>
</div>
<div>; res@tiMainString = "Modis vs PSP" ; title</div>
<div>; plt = gsn_csm_xy (wks,x,pltarry,res) ; create plot</div>
<div>; plt = gsn_csm_xy (wks,x,data,res) ; create plot</div>
<div> res = True</div>
<div> txres = True ; label BW line</div>
<div> txres@txFontHeightF = 0.0175 ; font height</div>
<div> txres@txJust = "CenterCenter" ; Set lable location</div>
<div><br>
</div>
<div> if (rcl_anova@b(0).gt.0) then</div>
<div> text = "AOD_PM2.5 = "+ sprintf("%5.3f", rcl_anova@b(1))+"*PM25 + "+sprintf("%5.3f", abs(rcl_anova@b(0)))</div>
<div> else</div>
<div> text = "AOD_PM2.5 = "+ sprintf("%5.3f", rcl_anova@b(1))+"*PM25 - "+sprintf("%5.3f", abs(rcl_anova@b(0)))</div>
<div> end if</div>
<div> plt = gsn_csm_xy (wks,x,pltarry,res) ; create plot</div>
<div> gsn_add_text(wks,plt,text, 70, 5.6,txres) </div>
<div> draw(plt)</div>
<div> frame(wks)</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
<div>; res@gsnMaximize = True ; maximize plot</div>
<div>; res@tiMainString = "Scatter Plot" ; add title</div>
<div>; res@xyMarkLineMode = "Markers" ; choose to use markers</div>
<div>; res@xyMarkers = 16 ; choose type of marker </div>
<div>; res@xyMarkerColor = "NavyBlue" ; Marker color</div>
<div>; res@xyMarkerSizeF = 0.01 ; Marker size (default 0.01)</div>
<div>;</div>
<div>; plot = gsn_xy (wks,x,y,res) ; create plot</div>
<div>end</div>
<br>
<br>
</div>
</div>
_______________________________________________<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></blockquote></div><br clear="all"><div><br></div>-- <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, </font></span><span><font color="#888888">Climate and Global Dynamics Laboratory, NCAR<br></font></span></div></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><span><font color="#888888">303-497-1726 </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>