Location and font of textbox when using FuncFit

Hi all,

I use FuncFit to do fitting with user-defined function for a set of data. I'd like to place textbox (textbox contains found fitting parameters and their errors) in each graph in specific location. I did the following:

FuncFit/Q/TBOX=768 myFunc W_coef w /D
TextBox/A=LT

But the command TextBox/A=LT doesn't change the location of textbox created using FuncFit. Is there any way to place textbox in specific location in graphs in code (not manual drag and drop)? And I'd like to change font size of text in textbox, is it possible?

I found how to change location of textbox:

TextBox/C/N=CF_wavename/X=0.00/Y=0.00

But I don't understand how to change font size without writing text of textbox. I found how to change font size with writing text:

TextBox/C/N=CF_wavename "\\Z08Coefficient values ± one standard deviation\r\ta\t=4.9649 ± 0.301\r\tb\t=10.744 ± 0.738"

It is possible if I change font size manually for some data, but I'd like to do it in code for large data set, and given that I don't know what text will be in textbox for each case. Please advise how to solve this problem.

Use the AnnotationInfo() function. The text of the annotation is contained in the TEXT keyword, but since the text itself could contain separator characters, it can be hard to unpack. We provide the Annotation Procs.ipf that has utility functions for dealing with the output of AnnotationInfo:

#include <AnnotationInfo Procs>

Especially, see the AnnotationText() function provided by that procedure file.

I wrote test function to generate data:

Function create_data(number)
    Variable number
    String s
    Variable i
    for (i=0; i<number; i+=1)
        s = "Wave"+num2str(i)
        Make/O/D/N=1000 $s=(i+1)*exp(-(p-500-10*i)^2/(2*100^2))+gnoise(0.1)
    endfor
End

Then I created fitting function:

Function mygauss(w,x) : FitFunc
    Wave w
    Variable x

    //CurveFitDialog/ These comments were created by the Curve Fitting dialog. Altering them will
    //CurveFitDialog/ make the function less convenient to work with in the Curve Fitting dialog.
    //CurveFitDialog/ Equation:
    //CurveFitDialog/ f(x) = a*exp(-(x-b)^2/(2*c^2))
    //CurveFitDialog/ End of Equation
    //CurveFitDialog/ Independent Variables 1
    //CurveFitDialog/ x
    //CurveFitDialog/ Coefficients 3
    //CurveFitDialog/ w[0] = a
    //CurveFitDialog/ w[1] = b
    //CurveFitDialog/ w[2] = c

    return w[0]*exp(-(x-w[1])^2/(2*w[2]^2))
End

Finally, I wrote function for fitting:

Function fitit()
    String name, name_tbox
    String list = WaveList("*",";","")
    Variable numItems = ItemsInList(list), ii
    for (ii=0; ii<numItems; ii+=1)
        name = StringFromList(ii,list)
        name_tbox = "CF_"+name
        Print "name_tbox = ", name_tbox
        Wave w = $name
        WaveStats/Q w
        Make/O/D/N=3 W_coef
        W_coef = {V_max, V_maxloc, 120}
        Display w
        ModifyGraph mode=3,marker=19,msize=1,rgb=(0,0,65535)
        FuncFit/Q/TBOX=768 mygauss W_coef w /D
        TextBox/C/N=name_tbox/X=0.00/Y=0.00
    endfor
End

But the last line

TextBox/C/N=name_tbox/X=0.00/Y=0.00

doesn't do anything. I don't understand why it doesn't change location of textbox in graphs. Could you please tell me, how should I change code to place textbox in specific location?

You may need to change the anchor point of the textbox. If you want it in the upper-left corner of your graph, use /A=LT.

You need to add a $ operator to your Textbox command:

TextBox/A=LT/C/N=$name_tbox

The clue for me was the tiny, blank textbox in the upper left corner of your graph. Those tiny textboxes all have the name "name_tbox". For more on the $ operator: DisplayHelpTopic "Converting a String into a Reference Using $" That description is mostly about waves, but this works pretty much anywhere our documentation says something is a "name" rather than a string containing a name.

In reply to by johnweeks

johnweeks wrote:

You need to add a $ operator to your Textbox command:

TextBox/A=LT/C/N=$name_tbox

The clue for me was the tiny, blank textbox in the upper left corner of your graph. Those tiny textboxes all have the name "name_tbox". For more on the $ operator: DisplayHelpTopic "Converting a String into a Reference Using $" That description is mostly about waves, but this works pretty much anywhere our documentation says something is a "name" rather than a string containing a name.

Thank you very much! Now it works!

Previously I tried to use /N=$name_tbox/X=0.00/Y=0.00, but without /A=LT. I thought that if I use /X=0.00/Y=0.00, then I don't need to use /A=LT.

In reply to by johnweeks

johnweeks wrote:

The /X and /Y positions are relative to the anchor point specified via /A.

I read now Igor Pro help regarding textbox /X option more attentively: "xOffset is the distance from anchor to textbox". Previously I didn't notice this.