Lazy method for coloring traces programmatically
One of the features I use a lot is the "Make Traces Different" GUI. It's very convenient, but I've never found a way to access it very easily from within a function. I'm posting this here in case anyone else is ever searching for a way to colorize the traces as part of a step in a function. There was an older forum post that got part of the way here, but it generated warnings whenever the "Make Traces Different" GUI wasn't already open in the experiment.
String preset_name
// Use the "Rainbow" color table by default, user can optionally override with:
// AutoColorize(preset_name="whatever")
If(ParamIsDefault(preset_name))
preset_name = "Rainbow"
EndIf
// Check to see if the panel is already open and behave accordingly
If(WinType("KBColorizePanel") == 7)
KBColorizeTraces#KBColorTablePopMenuProc("",0,preset_name)
Else
ShowKBColorizePanel()
KBColorizeTraces#KBColorTablePopMenuProc("",0,preset_name)
KillWindow KBColorizePanel
EndIf
End
As is, this can be called with no input and it'll default to the "Rainbow" color set. Overriding the parameter is optional and will work with any of the color sets included in the built-in GUI. It will apply to whatever the last selected (or generated) graph is.
It's a little sloppy and a little hackey BUT it has the benefit of not needing to carry around your own color table to assign.
For this to work you should ensure that the package file is included in the current experiment
#include <KBColorizeTraces>
otherwise your snippet will not compile.
Take a look at the file WMMenus.ipf if you want to understand how things work when you select something in a 'packages' submenu, like "Make Traces Different".
October 11, 2024 at 12:06 am - Permalink