Simultaneously set opacity for multiple traces (of different colors)

I've often got a plot overlaying traces in various colors, and then I want to change the opacity of multiple traces (without altering their unique rgb values). When I highlight these traces in the "Modify Trace Appearance" window and go to change the opacity in the Color drop down, it does set the opacity of all of them. However, it also sets them all to the same rgb (that of the top-most trace, it appears).

I think it would be better behavior if the opacity could be set independently from within the GUI window -- in the same way that changing (for example) trace mode (line, dots, etc) does not change trace color. 

I am not asking that the modifygraph command itself be changed (though programming also would also be easier if there was a separate ModifyGraph a(traceName)=opacity command). I am instead asking that the GUI handle it and run/produce commands that maintain the rgb of the selected traces, modifying only the opacity, (Unless, of course, a new color is also selected).

Very helpfully, this GUI window already does this in other situations. For example, when multiple traces with different error bar settings are highlighted and one setting (e.g., cap thickness) is changed, the GUI runs/produces commands that preserve the other unique error bar settings of each selected trace.

Hm. The alpha value is just another byte in a 32-bit color spec; it's usually thought of as just part of a color. I can see the utility of what you ask for, and I will have to say that implementing it is not straightforward. That's partly because the alpha is stored internally as part of a color setting. And there are a lot of colors in a graph.

Having said that, here is some Igor code that will set the alpha of all the trace colors in a graph. Note that it uses ModifyGraph rgb, so it will not separately set barStrokeRGB, mrkStrokeRGB, negRGB, or plusRGB, or the various usexxxrgb keywords. It could be modified to do so, though.

Select Window->New->Procedure, copy the code below, paste it into your new procedure window, and then select File->Save Procedure As. Navigate to your Igor Pro User Files folder and save the procedure in the Igor Procedures folder you find there. Now re-start Igor. You will find "Set All Traces Alpha" at the bottom of the Graph menu.

#include <Graph Utility Procs>

Menu "Graph"
    "Set All Traces Alpha", mSetAllTracesAlpha()
end

Function mSetAllTracesAlpha()

    String gname=WinName(0,1)
    Variable alpha=65535
    Prompt gname, "Graph:"
    Prompt alpha, "Alpha [0 to 65535]:"
    DoPrompt "Set All Traces Alpha", gname, alpha
    if (V_flag == 0)
        SetAllTracesAlpha(gname, alpha)
    endif
end

Function SetAllTracesAlpha(String gname, Variable alpha)

    if (strlen(gname) == 0)
        gname = WinName(0,1)
    endif
    if (strlen(gname) == 0)
        return 0
    endif
   
    Variable i
    String traces = TraceNameList(gname, ";", 1)
    Variable ntraces = ItemsInList(traces)

    for (i = 0; i < ntraces; i++)
        String tname = StringFromList(i, traces)
        String info = Traceinfo(gname, tname, 0)
        String color = WMGetRECREATIONInfoByKey("rgb(x)", info)
        String redstr = StringFromList(0, color, ",")
        Variable red = str2num(redstr[1,inf])
        Variable green = str2num(StringFromList(1, color, ","))
        Variable blue = str2num(StringFromList(2, color, ","))
        ModifyGraph rgb($tname)=(red, green, blue, alpha)
    endfor
end

 

Thanks for considering it. That code is helpful -- at some point, I'd like to make a listbox version (because I almost never want to make all the traces opaque, just a subset).

Right- I knew that you wouldn't actually want to change ALL the traces :)

The function I wrote could be modified to take the list string as an input. That would make it useful as the basic engine for the control panel you are envisioning.