Get the color of a trace on a graph

Paste the code below into an Igor procedure file and compile. Here is an example of how to use the code:

Make test
Display test
print GetTraceColor("Graph0", "test")
ModifyGraph rgb=(0,0,39168)
print GetTraceColor("Graph0", "test")

// Get the RGB triplet representing the color of a trace on a graph.
// @param graphName
//  A string containing the name of the graph.
// @param traceName
//  A string containing the name of the trace.
// @return
//  A string containing a comma separated list with the red, green,
//  and blue numeric values of the specified trace, or if there was
//  an error an empty string will be returned.
Function/S GetTraceColor(graphName, traceName)
    String graphName
    String traceName
    if (WinType(graphName) != 1)
        printf "There is not a graph named %s.\r", graphName
        return ""
    String info = TraceInfo(graphName, traceName, 0)
    if (strlen(info) <= 0)
        printf "There is not a trace named %s on graph %s.\r", traceName, graphName
        return ""
    String traceRecreation = info[strsearch(info, "RECREATION", 1), strlen(info) - 1]
    String traceColors = StringByKey("rgb(x)", traceRecreation, "=", ";")
    // Remove parenthesis from string.
    traceColors = RemoveEnding(traceColors[1, strlen(traceColors) - 1], ")")
    return traceColors             




Igor Pro 9

Learn More

Igor XOP Toolkit

Learn More

Igor NIDAQ Tools MX

Learn More