[ncl-talk] how to get rid of the front symbols in the legend?

dyjbean at gmail.com dyjbean at gmail.com
Tue Sep 20 07:59:13 MDT 2016


i referred the text_18.ncl , and give those figure.
the main script is as the below:
    ;************************************************
; plotting parameters
; This illustrates one approach. Overlays could also be used.
;************************************************
   rmfiles=systemfunc("rm "+"2010_678.png")
   wks  = gsn_open_wks("png","2010_678") 
   
   res              = True                     ; plot mods desired
   res at gsnMaximize  = True
   res at gsnDraw      = False                    ; Turn off draw and frame so
   res at gsnFrame     = False                    ; we can attach some text.
   
   txres =  True
   txres at txPerimOn  =  False
   txres at txFontHeightF = 0.02


   res1  =  True
   res1  =  res
   res1 at xyMarkLineModes     = (/"Markers","Lines"/)  ; choose which have markers
   res1 at xyMarkers           = 16                     ; choose type of marker 
   res1 at xyMarkerColor       = "red"                  ; Marker color
   res1 at xyMarkerSizeF       = 0.01                  ; Marker size (default 0.01)
   res1 at xyDashPatterns      = 1                       ; solid line 
   res1 at xyLineThicknesses   = (/1,2/)                ; set second line to 2
   res1 at tmYLFormat          = "f"                    ; not necessary but nicer labels 
   ;res1 at lgPerimOn           =  False
   res1 at tiYAxisString      =  "O3(DU)"
   res1 at tiXAxisString      =  "NO2(DU)"
   
   plot1  = gsn_csm_xy (wks,x1,pltarry1,res1)           ; create plot
   

;; bottom right string
   amres1_tr =  True
   amres1_tr at amParallelPosF  = 0.48
   amres1_tr at amOrthogonalPosF = 0.48
   amres1_tr at amJust   =  "BottomRight"
   
   ;; create text strings
   tr1_label = "y="+tostring(rc1)+"*x"+"+"+tostring(rc1 at yintercept)+"~C~"+"R~S~2~N~="+tostring(cod1)
   
   tx1res = True
   tx1res =  txres
   tx1res at txBackgroundFillColor = "white"
   tx1id_tr = gsn_create_text(wks,tr1_label,tx1res)

;; attach text strings to plot
   amid_tr1 = gsn_add_annotation(plot1,tx1id_tr,amres1_tr)
   
   
   res2  =  True
   res2  =  res
   res2 at xyMarkLineModes     = (/"Markers","Lines"/)  ; choose which have markers
   res2 at xyMarkers           = 16                     ; choose type of marker 
   res2 at xyMarkerColor       = "red"                  ; Marker color
   res2 at xyMarkerSizeF       = 0.01                  ; Marker size (default 0.01)
   res2 at xyDashPatterns      = 1                       ; solid line 
   res2 at xyLineThicknesses   = (/1,2/)                ; set second line to 2
   res2 at tmYLFormat          = "f"                    ; not necessary but nicer labels 
   ;res2 at lgPerimOn           =  False
   res2 at tiYAxisString      =  "O3(DU)"
   res2 at tiXAxisString      =  "CO(DU)"
   
   plot2  = gsn_csm_xy (wks,x2,pltarry2,res2)           ; create plot

;; bottom right string
   amres2_tr =  True
   amres2_tr at amParallelPosF  = 0.48
   amres2_tr at amOrthogonalPosF = 0.48
   amres2_tr at amJust   =  "BottomRight"

;; create text strings
   tr2_label = "y="+tostring(rc2)+"*x"+"+"+tostring(rc2 at yintercept)+"~C~"+"R~S~2~N~="+tostring(cod2)
   
   tx2res = True
   tx2res =  txres
   tx2res at txBackgroundFillColor = "white"
   tx2id_tr = gsn_create_text(wks,tr2_label,tx2res)


;; attach text strings to plot
   amid_tr2 = gsn_add_annotation(plot2,tx2id_tr,amres2_tr)
   
   ;---Draw both plot in a panel.
   pres                  = True
   pres at gsnMaximize      = True
   ;pres at gsnPanelLabelBar = True
   pres at txString           = "2010 summer" 
   ;pres at pmLabelBarWidthF = 0.6
   pres at lbLabelFontHeightF  = 0.03              ; make labels smaller

   gsn_panel(wks,(/plot1,plot2/),(/1,2/),pres)




dyjbean at gmail.com
 
From: Dennis Shea
Date: 2016-09-20 20:38
To: dyjbean soybean
Subject: Re: Re: [ncl-talk] how to get rid of the front symbols in the legend?
On the Applications page:  http://www.ncl.ucar.edu/Applications/

See "Text" ...there are numerous examples. 
You do not need to use the 'legend' class. This does the marker and text.

Many Applications show how to add text only. For examples:
See the Boorstarp link
;***************************************************************
;--- text object original sample statistics 
;***************************************************************
   txres                       = True
   txres at txFont                = "helvetica-bold"
   txres at txFontHeightF         = 0.0150
   textSample  = (/"  Mean="+sprintf("%5.1f", xAvg) +"~C~"+  \
                   "   Std="+sprintf("%5.1f", xStd) +"~C~"+  \
                   "  Skew="+sprintf("%5.2f", xSkew) +"~C~"+  \
                   "  Kurt="+sprintf("%5.2f", xKurt) +"~C~"+  \
                   "  xLow="+sprintf("%5.1f", xLow) +"~C~"+  \
                   "  xMed="+sprintf("%5.1f", xMed) +"~C~"+  \
                   "   xHi="+sprintf("%5.1f", xHi ) /)
   txBoxSample  = gsn_create_text(wks,textSample, txres)
   amres  = True
   amres at amParallelPosF   =  0.30             ; move legend to the right
   amres at amOrthogonalPosF = -0.30             ; move the legend up
   annoSample = gsn_add_annotation(hstSample, txBoxSample, amres)  ; Attach string to plot

You can change this for your application.
-----------

In the future, please send questions to ncl-talk only.  We just can not answer individual questions.

On Mon, Sep 19, 2016 at 8:14 AM, dyjbean soybean <dyjbean at gmail.com> wrote:
my purpose is to keep R-squared and the fitting term, and get rid of the front black line and red point.

like the above result.





dyjbean at gmail.com
 
From: Dennis Shea
Date: 2016-09-19 21:40
To: dyjbean soybean
Subject: Re: [ncl-talk] how to get rid of the front symbols in the legend?
This is offline. I do not know the answer to the question posted.

However, The number of decimal places is rather large.

You use:   

   tostring(rc1)

I suggest looking at

   http://www.ncl.ucar.edu/Document/Functions/Built-in/sprintf.shtml

This allows the user to print a user desired number of decimal places:

   
sprintf("%5.2f", rc1)
sprintf("%5.2f", rc1 at yintercept)

Of course the 5.2 could be 6.3 or .... whatever

On Mon, Sep 19, 2016 at 7:13 AM, dyjbean soybean <dyjbean at gmail.com> wrote:

hi, 
   i ploted a figure with fitting function and R-squared coefficient in the legend showed below:
  in the legend , there are symbols black solid line and red point existing in the front of R-squared and the fitting function, 
i want to get rid of the black solid line and red point in the legend,and only leave the behind expression.
but i don't know which attribute can be assigned in my script as following:
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
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"

begin
;************************************************
; Read data from file [time, value]. 
; Missing values (_FillValue) indicated by -9999.0
;************************************************

   txtfiles=systemfunc("ls *.txt")
   nfiles=dimsizes(txtfiles)

   do i=0,nfiles-1

   ncol  = 3
   ;nrow  = systemfunc("wc -l "+txtfiles(i))
   nrow  = numAsciiRow(txtfiles(i))
   data  = asciiread(txtfiles(i), (/nrow,ncol/), "float")
   data at _FillValue = -999.0 

   y     = data(:,0)              ; O3             
   x1    = data(:,1)              ; NO2
   x2    = data(:,2)              ; CO
   
   xvaro3=variance(y)

;************************************************
; calculate the regression coefficient (slope)    
;************************************************
   rc1    = regline(x1, y)          ; slope           
   rc1 at units = "DU"         
   print(rc1)

   x1resvaro3 = variance((y-(rc1*x1+rc1 at yintercept)))
   cod1 =  1.0-(x1resvaro3/xvaro3)

   rc2    = regline(x2, y)          ; slope           
   rc2 at units = "DU"         
   print(rc2)
   
   x2resvaro3 = variance((y-(rc2*x2+rc2 at yintercept)))
   cod2 =  1.0-(x2resvaro3/xvaro3)

;************************************************
; create an array to hold both the original data
; and the calculated regression line   
;     ---------
;     y = mx+b 
;     m is the slope:       rc      returned from regline
;     b is the y intercept: rc at yave attribute of rc returned from regline
;************************************************

;;; O3->NO2  
   pltarry1   = new ( (/2,nrow/), typeof(data), data at _FillValue)

   pltarry1(0,:) = y                                 ; use markers
   pltarry1(1,:) = rc1*(x1-rc1 at xave) + rc1 at yave          ; use solid line

;;;; O3->CO
   pltarry2   = new ( (/2,nrow/), typeof(data), data at _FillValue)

   pltarry2(0,:) = y                                 ; use markers
   pltarry2(1,:) = rc2*(x2-rc2 at xave) + rc2 at yave      ; use solid line
   

;************************************************
; plotting parameters
; This illustrates one approach. Overlays could also be used.
;************************************************
   rmfiles=systemfunc("rm "+"2010_678.png")
   wks  = gsn_open_wks("png","2010_678") 
   
   res                     = True                   ; plot mods desired
   res at gsnDraw               = False
   res at gsnFrame              = False
   res at xyMarkLineModes     = (/"Markers","Lines"/)  ; choose which have markers
   res at xyMarkers           = 16                     ; choose type of marker 
   res at xyMarkerColor       = "red"                  ; Marker color
   res at xyMarkerSizeF       = 0.01                  ; Marker size (default 0.01)
   res at xyDashPatterns      = 1                       ; solid line 
   res at xyLineThicknesses   = (/1,2/)                ; set second line to 2
   res at tmYLFormat          = "f"                    ; not necessary but nicer labels 
   ;res at lgPerimOn           =  False

   res at pmLegendDisplayMode    = "Always"            ; turn on legend

     ;res at tiMainString        = "Output from regline"  ; title
   res1  =  True
   res1  =  res
   
   ;res1 at lgLineLabelsOn  =  False
   res1 at pmLegendSide           = "Bottom"               ; Change location of 
   res1 at pmLegendParallelPosF   = .63                 ; move units right
   res1 at pmLegendOrthogonalPosF = -0.5                ; move units down
 
   res1 at pmLegendWidthF         = 0.15                ; Change width and
   res1 at pmLegendHeightF        = 0.18                ; height of legend.
   res1 at lgLabelFontHeightF     = .02                 ; change font height

   res1 at tiYAxisString      =  "O3(DU)"
   res1 at tiXAxisString      =  "NO2(DU)"
   

   ;; it function and R-squared
   x1ff ="y="+tostring(rc1)+"*x"+"+"+tostring(rc1 at yintercept)
   x1fr2="R~S~2~N~="+tostring(cod1)

   print(x1ff)
   print(x1fr2)

   res1 at xyExplicitLabels   =(/x1ff,x1fr2/)
   
   plot1  = gsn_csm_xy (wks,x1,pltarry1,res1)           ; create plot

   res2  =  True
   res2  =  res
   
   ;res2 at lgLineLabelsOn  =  False
   res2 at pmLegendSide           = "Bottom"               ; Change location of 
   res2 at pmLegendParallelPosF   = .65                 ; move units right
   res2 at pmLegendOrthogonalPosF = -0.5                ; move units down
 
   res2 at pmLegendWidthF         = 0.15                ; Change width and
   res2 at pmLegendHeightF        = 0.18                ; height of legend.
   res2 at lgLabelFontHeightF     = .02                 ; change font height

   res2 at tiYAxisString      =  "O3(DU)"
   res2 at tiXAxisString      =  "CO(DU)"


   ;; fit function and R-squared
   x2ff = "y="+tostring(rc2)+"*x"+"+"+tostring(rc2 at yintercept)
   x2fr2 = "R~S~2~N~="+tostring(cod2)

   res2 at xyExplicitLabels   =(/x2ff,x2fr2/)

   plot2  = gsn_csm_xy (wks,x2,pltarry2,res2)           ; create plot
   
   ;---Draw both plot in a panel.
   pres                  = True
   pres at gsnMaximize      = True
   ;pres at gsnPanelLabelBar = True
   pres at txString           = "2010 summer" 
   ;pres at pmLabelBarWidthF = 0.6
   pres at lbLabelFontHeightF  = 0.01              ; make labels smaller

   gsn_panel(wks,(/plot1,plot2/),(/1,2/),pres)

   delete([/pltarry1,pltarry2/])
   delete([/res,res1,res2/])
   delete([/rc1,rc2/])
   delete(data)
   delete([/x1resvaro3,x2resvaro3,cod1,cod2/])
   delete([/x1ff,x1fr2,x2ff,x2fr2/])
   
   

 end do


end

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
 any help would be appreciated!





dyjbean at gmail.com

_______________________________________________
ncl-talk mailing list
ncl-talk at ucar.edu
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20160920/355c20ab/attachment-0001.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/png
Size: 111295 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20160920/355c20ab/attachment-0003.png 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/png
Size: 12734 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20160920/355c20ab/attachment-0004.png 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/png
Size: 106014 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20160920/355c20ab/attachment-0005.png 


More information about the ncl-talk mailing list