Setting Colors of traces and a subset for legend
hegedus
Just looking to see if there is a starting point before I start from scratch on this task.
Task: I have a display that shows two sets of graphs. The same X-Axis and 2 separate Y-Axis that show data from experiments in two different ways. Nothing magical here. I use a multidimensional wave to store the data and am plotting different columns
If I look at the tracenamelist: B7;B7#1;B8;B8#1;B9;B9#1;B6;B6#1;B5;B5#1; I have the 2 traces for each data set. The traces are added via a function and the traces are basically added in pairs, i.e. B7#1 is appendedtograph immediately after B7.
Goal 1: Have the traces from the same originating data set be the same color, i.e. B7 and B7#1 are the same and B8 and B8#1 (and different from B7)...
Note there is not a defined number of sets. I use a wave widget to let the user pick the data to display and compare.
Goal 2: Create a legend with the wave symbol, but include only one instance of the pair, i.e. B7 would be included, but B7#1 would not. Since the they are the same color and represent data from the same set labeling them separately would be redundant.
I found a solution and thought I would post it for posterity's sake. I used the CommonColors function from the "Make Traces Different" code provided by Wavemetrics. Modifications:
1. Since I know the number of traces in my code I use it as input instead of using the function within the original.
2. I included a grouping variable the allows me to set the number of like colored traces.
Variable numTraces
Variable Grouping
String graphName = WinName(0, 1)
if (strlen(graphName) == 0)
return -1
endif
if (numTraces <= 0)
return -1
endif
Variable red, green, blue
Variable i, index
for(i=0; i<numTraces; i+=1)
index = (mod(floor(i/grouping), 10)) // Wrap after 10 traces.
switch(index)
case 0:
red = 0; green = 0; blue = 0;
break
case 1:
red = 65535; green = 16385; blue = 16385;
break
case 2:
red = 2; green = 39321; blue = 1;
break
case 3:
red = 0; green = 0; blue = 65535;
break
case 4:
red = 39321; green = 1; blue = 31457;
break
case 5:
red = 48059; green = 48059; blue = 48059;
break
case 6:
red = 65535; green = 32768; blue = 32768;
break
case 7:
red = 0; green = 65535; blue = 0;
break
case 8:
red = 16385; green = 65535; blue = 65535;
break
case 9:
red = 65535; green = 32768; blue = 58981;
break
endswitch
ModifyGraph rgb[i]=(red, green, blue)
endfor
End
June 12, 2009 at 08:26 am - Permalink