<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body 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>
</body>
</html>