Unconnect waves in graph
To display a number of different waves, I use the AppendToGraph function. See the code to see how. I would like to plot currents (the Y-values) against their voltages (the X-values). The plotmode is set to lines, or lines and markers. This works fine, except for the fact that all the different current waves are connected to the previous one. I would like the individual values of each current wave to be connected, but not the waves themselves to be connected to each other.
I noticed that when I plot every current wave against one single voltage wave (in the same way) I get what I want. However, I really need to plot the current values against their own voltage value.
Is there a way to get what I want?
String Xwave = "meanCurrents"
String YWave = "meanVoltages"
String current_waves = "Current"
Variable index = 0
String graphicName = "IV_Plot"
String these_Waves = WaveList(current_waves + "*",";","")
do // for every wave to add
String /G this_wave = StringFromList(index, these_Waves)
if (strlen(this_Wave) == 0)
break
else
plotGraph(graphicName, Xwave, Ywave, index)
endif
index += 1
while(1)
end
//####################################################
Function plotGraph(graphName,the_wave, the_xaxis ,i)
String graphName
String the_wave
String the_xaxis
Variable i
if (i ==0)
display /N=$(graphName) $the_wave vs $the_xaxis
else
AppendToGraph /W=$(graphName) $the_wave vs $the_xaxis
endif
end
Olav
If that's the case, your code might be confused. You're using the wave "meanCurrents" for your Xwave and "meanVoltages" for your Ywave. You might have these switched.
Also, you iterate through theseWaves one at a time, but then you don't do anything with thisWave. I assume you'd need to pass that to your plotGraph() function as a parameter, but instead you're passing xWave, Ywave each time, and since the value of those strings isn't changing in the do...while loop you're probably not getting what you'd expect.
October 28, 2008 at 11:25 am - Permalink
The code is actually a little more complicated than I posted. I tried to isolate the part that (i thought) generated the weird graph. I attached the graph now. I probably screwed up 'simplifying'. Below is the complete code, as it is actually working in Igor.
You can also see that the first time 'plotGraph()' is called, it uses the same X-axis every loop.
I alos attached two .txt files that I use to try this script.
Thanks for all your advice. I really appreciate it!
Olav
#include <TransformAxis1.2>
//########################################################################
Function processfile(folder)
String folder
Newpath/O /Q datadir, folder // a new symbolic path name; suppressed printing path information in the history (=/Q)
String fileName // a string holding the filename
Variable index = 0 // indicating the index-th file
String current_waves = "Current" // the name of the waves that contain current-traces (these names are set in proc. loadcsf()).
String voltage_waves = "Voltage" // the name of the waves that contain voltage-traces (these names are set in proc. loadcsf()).
String xAxis = "Time1" // the name of the wave that will be used by 'graphframe' as x-axis. This one is global.
do // get filename
fileName = IndexedFile(datadir, index ,".txt") // get the name of the index-th txt-file out of the folder 'datadir'
if (strlen(fileName) == 0) // if 'filename' is empty,
break // break out of loop
endif
loadcsf(folder, fileName) // first load a csf-file into wave
// Here are parameters set-up for what needs to be done in the next do-while loop
String meanCurrents = ReplaceString(".txt", fileName, "") + "_I" // create name for the new wave that will hold the means
makewave(xAxis, current_waves, fileName, meanCurrents) // create new wave with the name set above
Wave mean_currents = $(meanCurrents) // the wave 'mean_currents' will represent the name contained i meanCurrens
Variable j = 0 // indicating the j th frame
String /G these_Waves = WaveList(current_waves + "*",";","") // get a semicolon-separated list of strings containing the
// names of all waves matching "Current*"
String /G plotName = "Currents_" + ReplaceString(".txt", fileName, "") // name of the plot created during the while loop
do
String /G this_wave = StringFromList(j, these_Waves) // work on the j th frame from 'these_Waves'
if (strlen(this_wave) == 0) // no more frames?
break // break out of loop
else
plotGraph(plotName,this_wave, xaxis,j) // This will result in the current frame being plotted
placeCursors(plotName,this_wave,5395,5495) // Place cursors in this frame
mean_currents[j]= calcMean(this_wave) // calcaulate a the mean between cursors and put in wave 'mean_currents'
endif
j += 1 // this one is for looping through the designated waves
while(1)
KillWindow $(plotName)
String meanVoltages = ReplaceString(".txt", fileName, "") + "_V" // create name for the new wave that will hold the means
makewave(xAxis, voltage_waves, fileName, meanVoltages) // create new wave with the name set above
Wave mean_voltages = $(meanVoltages) // the wave 'mean_voltages' represents the name contained in meanVoltages
Variable k = 0 // indicating the k th frame
String /G these_Waves = WaveList(voltage_waves + "*",";","") // get a semicolon-separated list of strings containing the
// names of all waves matching "Current*"
String /G plotName = "Voltages_" + ReplaceString(".txt", fileName, "") // name of the plot created during the do-while loop
do
String /G this_wave = StringFromList(k, these_Waves) // work in the k th frame of 'these_waves'
if (strlen(this_wave) == 0) // no more frames?
break // break out of loop
else
plotGraph(plotName,this_wave, xaxis, k) // plot the current fram
placeCursors(plotName,this_wave, 5395,5495) // place cursors in the current frame
mean_voltages[k]= calcMean(this_wave) // calculate mean between cursors and put in wave 'mean_voltages'
endif
k += 1 // this one is for looping through the designated waves
while(1)
KillWindow $(plotName)
String graphicName = "IV_Plot" // the name of the plot that is formed next
plotGraph(graphicName,meanCurrents, meanVoltages, index)
index +=1 // this one is for looping through the files
while(1)
removewaves()
end
//########################################################################
Function plotGraph(graphName,the_wave, the_xaxis ,jndex)
String graphName
String the_wave
String the_xaxis
Variable jndex
if (jndex ==0)
display /N=$(graphName) $the_wave vs $the_xaxis
else
AppendToGraph /W=$(graphName) $the_wave vs $the_xaxis // $-sign is needed here!! See <displayHelpTopic "Converting a String into a Reference Using $">
endif
end
//########################################################################
Function calcMean(theWave)
string theWave
Variable CursorA = pcsr(A) // set the variable to the location of the Cursors
Variable CursorB = pcsr(B)
Variable meanBC = mean($theWave,CursorA, CursorB) // calculate the mean of the values between the cursors
return meanBC // return the value to where the routine was called from
end
//########################################################################
Function placeCursors(graphName,the_wave, here, there)
String graphName // the name of the plot
String the_wave // the wave to place the cursors in
Variable here // location (row number) of the cursors
Variable there
Cursor/P /W=$(graphName) A, $the_Wave, here // plaats de cursos
Cursor/P /W=$(graphName)B, $the_Wave, there
end
//########################################################################
Function makewave(x_axis, waves_name, fileName, newWaveName)
String x_axis // the name of the x-axis
String waves_name // part of the names of waves that all waves share; from these waves a variable will be calclated and put in a new wave
String fileName // the filename from which to process the frames
String newWaveName
String these_Waves = WaveList(waves_name + "*",";","") // get a semicolon-separated list of strings containing the
// names of all waves matching "Current*"
Variable numwaves = ItemsInList(these_Waves,";") // contains the number of items in the list 'CurrentWaves'.
Make/N=(numwaves) $(newWaveName) // make new wave with 'numWaves' values in it, and
// name 'newWaveName.
Wave calculatedValues = $(newWaveName) // creates a local reference to a wave accessed in the
// body of a user-defined function.
end
//########################################################################
Function loadcsf(pathTofile, fileName)
String pathToFile
String fileName
Newpath/O /Q datapath, pathToFile // a new symbolic path name; suppressed printing path information in the history (=/Q)
String columnInfoString = "" // the string holding the names for the waves.
columnInfoString += "N='Time1'; N='Current1'; N='Voltage1';"
columnInfoString += "N='Time2'; N='Current2'; N='Voltage2';"
columnInfoString += "N='Time3'; N='Current3'; N='Voltage3';"
columnInfoString += "N='Time4'; N='Current4'; N='Voltage4';"
columnInfoString += "N='Time5'; N='Current6'; N='Voltage7';"
columnInfoString += "N='Time8'; N='Current8'; N='Voltage8';"
columnInfoString += "N='Time9'; N='Current9'; N='Voltage9';"
columnInfoString += "N='Time10'; N='Current10'; N='Voltage10';"
columnInfoString += "N='Time11'; N='Current11'; N='Voltage11';"
columnInfoString += "N='Time12'; N='Current12'; N='Voltage12';"
columnInfoString += "N='Time13'; N='Current13'; N='Voltage13';"
columnInfoString += "N='Time14'; N='Current14'; N='Voltage14';"
columnInfoString += "N='Time15'; N='Current15'; N='Voltage15';"
columnInfoString += "N='Time16'; N='Current16'; N='Voltage16';"
columnInfoString += "N='Time17'; N='Current17; N='Voltage17';"
columnInfoString += "N='Time18'; N='Current18'; N='Voltage18';"
columnInfoString += "N='Time19'; N='Current19'; N='Voltage19';"
columnInfoString += "N='Time20'; N='Current20'; N='Voltage20';"
loadWave/J /A /B=columnInfoString /P=datapath /Q fileName // load a delimeted text file(= /J) from path
// 'datadir' (= /P) with name 'filename' without
// the name wave dialog (=/A) and names for
// individual waves in 'columnInfoString'.
// Suppresses the messages in the history (=/Q)
end
//########################################################################
Function removeWaves()
KillWaves/A /Z // kills all waves in the current data folder (=/A) that are not currently in use
// (i.e. not in a graph table or other window).
end
October 28, 2008 at 01:26 pm - Permalink
It's amazing the stuff that you can do with Igor Pro! I am still only in the trial period, but the interface, flexibility and capabilities are really impressive. To me, it's no match for Origin (the software that is mainly used at the lab where I work). And I have a feeling I am now merely using some pretty simple functionalities.
Again, thanks for the input.
Here's my fix: (I'm sure all these could be done a lot more elegant, but I wanted to write this quickly just so I know what I can do with Igor)
plotGraph(graphicName,meanCurrents, meanVoltages, index)
index +=1 // this one is for looping through the files
while(1)
removewaves()
end
was replaced by:
if (index == 0)
variable left = 0 + (index * 401)
variable top = 0
variable right = 400 + (index * 401)
variable bottom = 250
Display /N=$(graphicName) /L=VertCrossing/B=HorizCrossing /W=(left, top, right, bottom) mean_currents vs mean_voltages
removewaves()
else
AppendToGraph /W=$(graphicName) /L=VertCrossing/B=HorizCrossing mean_currents vs mean_voltages
removewaves()
endif
ModifyGraph /W=$(graphicName) freePos(VertCrossing)={0,HorizCrossing};DelayUpdate
ModifyGraph /W=$(graphicName) freePos(HorizCrossing)={0,VertCrossing};DelayUpdate
ModifyGraph /W=$(graphicName) mode=4,marker=8,mrkThick=0.8,lsize=1.25,rgb=(37364,14262,8044);DelayUpdate
ModifyGraph /W=$(graphicName) useMrkStrokeRGB=1,mrkStrokeRGB=(37364,14262,8044)
ModifyGraph /W=$(graphicName) lblPosMode=4,lblPos=-10,lblLatPos(VertCrossing)=-80;DelayUpdate
ModifyGraph /W=$(graphicName) lblLatPos(HorizCrossing)=-175,lblRot(VertCrossing)=-80;DelayUpdate
Label /W=$(graphicName) VertCrossing "I (nA)";DelayUpdate
Label /W=$(graphicName) HorizCrossing "V (mV)"
removewaves()
index +=1 // this one is for looping through the files
while(1)
removewaves()
end
October 28, 2008 at 02:34 pm - Permalink
It looks like your problem is that your X values (voltage values) are not in numerical order. Therefore, Igor just connects the dots, and your graph looks wrong.
To fix this, you'll want to sort both your current and voltage waves, using the voltage wave as the key. You can do this by going to Analysis->Sort, and chose the voltage wave in the left list box and both the voltage and current waves in the right list box. The Igor command to do this should look like the following:
Sort JB133_005_V JB133_005_I,JB133_005_V
Is this the output you're looking for?
October 28, 2008 at 02:56 pm - Permalink
As a note, the LinkDisplay routines found here might be useful to you. They allow you to use a "simpler" nomenclature to display (x,y) wave pairs. For example, if you want to display all waves in the current folder found by a search of "Current*" against a wave called Time1, you could do this ...
display
linkdisplay#lappendtograph(WaveList("Current*",";",""))
HTH
--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAH
October 28, 2008 at 04:01 pm - Permalink