Legend Name from a Wavelist
ctmckee
For example:
I have a graph with 4 waves all named ScaledY (from different folders). So the legend automatically comes up as ScaledY,ScaledY#1....
I want to use a wavelist to populate the legend names in function.
If I can't do that, is there some other solution?
Thanks,
Clayton
--Jim Prouty
Software Engineer, WaveMetrics, Inc.
July 25, 2012 at 11:24 am - Permalink
Sorry, I wasn't clear in my post. I don't want to generate a legend that uses the actual names from the TraceNameList:
Example:
Each wave in graph is named ScaledY, so TraceNameList for 4 traces pumps out ScaledY;ScaledY#1;ScaledY#2;ScaledY#3.
I want to generate new names for the legend (without renaming wave names in graph) using a wavelist of something like ScaledY_200nm; ScaledY_300nm;ScaledY_400nm;ScaledY_500nm....
Here's the code I'm trying to write for this:
variable index
string list
list=wavelist("yvalues*",";","") ///This list is used to setdatafolder....I also want to use it to name the traces in the legend...without renaming waves
string wavesinlist
string savedDF=getdatafolder(1)
dowindow/K results
do
wavesinlist = stringfromlist(index,list)
if(strlen(wavesinlist)==0)
break
else
setdatafolder wavesinlist
if (index==0)
display/N=Results/w=(500,300,1000,600) ScaledY vs Time_min
Legend/C/N=text0/F=0 //////THIS IS WHERE I WANT TO POPULATE THE LEGEND WITH THE WAVELIST AND NOT THE ACTUAL TRACE NAMES
else
appendtograph/W=Results ScaledY vs Time_min
endif
endif
setdatafolder SavedDf
index+=1
while(1)
end
July 25, 2012 at 11:55 am - Permalink
You can make your own Legend using a Textbox. Using your example names above, the text which reproduces the first line of the legend would look like
you can get the names from a wavelist, or any list, or textwave, and place it in like so:
Sorry I haven't written out full code here, but this should be a good starting point for you.
July 25, 2012 at 12:15 pm - Permalink
This set of functions might be helpful ...
string theList = TraceNameList("",";",1)
variable ic, nt = ItemsInList(theList)
for (ic=0;ic<nt;ic+=1)
wave ww = WaveRefIndexed("",ic,1)
print ExpandedTraceName(ww)
endfor
return 0
end
Function/S ExpandedTraceName(ww)
wave ww
string wdf = GetWavesDataFolder(ww,0)
string wn = NameofWave(ww)
return (wn + "_" + wdf)
end
--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAHuntsville
July 25, 2012 at 12:52 pm - Permalink
Fun bit of code. For a newbie programmer, it was bit like magic having that function pump out my original waves that I wanted to have named in my graph. Took me a minute to learn how the function worked, so thanks for that.
I still had the problem of generating a legendstr from the output. Not that I couldn't do it for a particle instance of a graph (e.g. if I always new there'd be X# of waves), rather it's difficult to generate a legendstr that will vary based on the number of waves that the graph may contain.
I've opted for simply renaming the generic instance name of the waves to wave names I want.
Thanks for the code.
Cheers
Clayton
July 26, 2012 at 08:35 am - Permalink
Perhaps I mis-understand. So, let me repeat what I think you are saying.
You can generate a legend text for a static instance of a given graph. In fact, you are fairly sure that you can code a function to do this. However, once a graph changes by the addition or subtraction of a trace, the legend needs to be revised. Then, you are lost.
If so, my suggestion from a "brute force" approach is to code a function that only generates a legend (CreateLegend()), nothing else. Then, code a function to create your graph(s). Run each function separately. When you change a graph with an existing set of traces by adding or removing a trace, delete the outdated legend and regenerate it with your CreateLegend() function.
Does this help in any way to solve the problem you are still facing?
--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAHuntsville
July 26, 2012 at 05:40 pm - Permalink
This part is rather simple. Just use tracenamelist to get the traces on the graph, then use itemsinlist to get the number of traces on the graph. This will control the for loop which creates the legend text.
variable i, num = itemsinlist(list, ";")
for (i=0; i<num; i+=1) //for loop adding a legend item for each trace
lgntext = "\s("+stringfromlist(i, list, ";") + ") "+ "trace label" + "\r"
endfor
lgntext=removeending(lgntext, "\r") //remove last carraige return
textbox/a=RT lgntext
Of course, where I've written "trace label" is just a place holder. This is where you will enter the names you want to appear on the legend, as previously discussed in this thread.
July 27, 2012 at 04:46 am - Permalink