Color traces on graph

Menu "Macros"
    "Color waves.../1", ColorWaves() //Ctrl+1
End

Macro ColorWaves()
    Variable rev = 1
    String colorTable = "RainbowCycle"
    ColorTraces(rev, colorTable)
End

Function ColorTraces( rev, colorTable )
//% V1.5
    Variable rev
    String colorTable
   
    String list = TraceNameList( "", ";", 1 )
    Variable numItems = ItemsInList( list )
    if ( numItems == 0 )
        return 0
    endif
   
    ColorTab2Wave $colorTable
    Wave M_colors  
   
    Variable index, traceindex
    for( index = 0; index < numItems; index += 1 )         
        Variable row = ( index/numItems )*DimSize( M_Colors, 0 )
        traceindex = ( rev == 0 ? index : numItems - index )
        Variable red = M_Colors[ row ][ 0 ], green = M_Colors[ row ][ 1 ], blue = M_Colors[ row ][ 2 ]
        ModifyGraph/Z rgb[ traceindex ] = ( red, green, blue )
    endfor

    KillWaves/Z M_colors
End
This provides a popup for the color tables:
Macro ColorWaves(rev, colorTable)
    Variable rev = 1
    Prompt rev, "1 for Reverse, else 0"
    String colorTable = "RainbowCycle"
    Prompt colorTable, "Color Table", popup, CTabList()
    ColorTraces(rev, colorTable)
End


I didn't propose a popup for the rev, because it'd change the values from 0 and 1 to 1 and 2.

--Jim Prouty
Software Engineer, WaveMetrics, Inc.
The snippet has an off-by-one bug in the reverse case. the traceindex calculation should be as follows:
traceindex = ( rev == 0 ? index : numItems-1 - index )
Hi,
I may be mistaken but I think the row variable also has an off-by-one index error - not a big deal on a large colortable and many traces, but I think the line below would allow you to have traces filling out the full spectrum of the color table:

Variable row = ( index/(numItems-1) )*DimSize( M_Colors, 0 )

Forum

Support

Gallery

Igor Pro 9

Learn More

Igor XOP Toolkit

Learn More

Igor NIDAQ Tools MX

Learn More