Is there a way to detect whether or not error bars have been applied to a trace in a graph? The recreation macro generated by the "traceinfo" command does not appear to contain any error bar options, and I cannot see any other way to get the status of or information on traces in a graph.
For example, to find out whether Error Bars are present in a Graph you can use the following Function:
strsearch(WinRecreation("Graph0",0),"ErrorBars",0)
It returns -1 if no error bars are present in Graph0, otherwise it will be positive.
and more specifically, the Function:
strsearch(WinRecreation("Graph0",0),"ErrorBars wave0",0)
returns positive if error bars are on trace wave0 in Graph0.
I have not checked whether this works in all cases.
Indeed, the presence of flags for things like the bar and cap width would cause problems with the simple check for "ErrorBars wave0". Here's a function that does the trick:
Function ErrorBarsArePresent(gname, trace)String gname, trace
if(strlen(gname) == 0)
gname = WinName(0,1)// top graph windowendifif(strlen(trace) == 0)returnstrsearch(WinRecreation(gname,0),"ErrorBars",0)>= 0// simple existence of error barsendifString winrec = WinRecreation(gname,0)Variable nlines = ItemsInList(winrec, "\r")Variableifor(i = 0; i< nlines; i += 1)String oneline = StringFromList(i, winrec, "\r")if(strsearch(oneline,"ErrorBars",0)>= 0)if(strsearch(oneline, trace+" ", 0)>= 0)// space prevents finding trace "wave0x" when you ask for "wave0"return1endifendifendforreturn0end
The input "gname" is the name of a graph window. Use "" to apply this to the top graph window.
The input "trace" can be "" to check for the simple presence of error bars on any trace in the graph. Otherwise, it names a trace like "wave0" or "wave0#1".
The code views the recreation macro as a list of command lines separated by carriage returns.
Thanks for this code, I found this helpful myself as well.
I've made a similar function to actually return the TraceName of the Error Bars. This function could no doubt be written better, but hopefully it can help someone just as the above code helped me.
To work, this function assumes that your error bar is a +/- wave on the Y variable.
Function/S ErrorBarsTraceName(gname, trace)// copied mostly from ErrorBarsArePresent on IgorExchangeString gname, trace
if(strlen(gname) == 0)
gname = WinName(0,1)// top graph windowendifif(strlen(trace) == 0)// you should always pass a trace name so that code does not come herereturn""endifString winrec = WinRecreation(gname,0)Variable nlines = ItemsInList(winrec, "\r")Variableifor(i = 0; i< nlines; i += 1)String oneline = StringFromList(i, winrec, "\r")if(strsearch(oneline,"ErrorBars",0)>= 0)if(strsearch(oneline, trace+" ", 0)>= 0)// space prevents finding trace "wave0x" when you ask for "wave0"
oneline=StringFromList(2,oneline,",")
oneline=StringFromList(0,oneline,")")return oneline
endifendifendforreturn""end// ErrorBarsTraceName
For example, to find out whether Error Bars are present in a Graph you can use the following Function:
strsearch(WinRecreation("Graph0",0),"ErrorBars",0)
It returns -1 if no error bars are present in Graph0, otherwise it will be positive.
and more specifically, the Function:
strsearch(WinRecreation("Graph0",0),"ErrorBars wave0",0)
returns positive if error bars are on trace wave0 in Graph0.
I have not checked whether this works in all cases.
Hope this helps!
Kurt
January 24, 2013 at 11:17 pm - Permalink
The input "gname" is the name of a graph window. Use "" to apply this to the top graph window.
The input "trace" can be "" to check for the simple presence of error bars on any trace in the graph. Otherwise, it names a trace like "wave0" or "wave0#1".
The code views the recreation macro as a list of command lines separated by carriage returns.
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
January 25, 2013 at 09:39 am - Permalink
January 25, 2013 at 11:07 pm - Permalink
I've made a similar function to actually return the TraceName of the Error Bars. This function could no doubt be written better, but hopefully it can help someone just as the above code helped me.
To work, this function assumes that your error bar is a +/- wave on the Y variable.
April 2, 2013 at 09:36 am - Permalink
--Jim Prouty
Software Engineer, WaveMetrics, Inc.
April 2, 2013 at 11:55 am - Permalink