PDA

View Full Version : gnuplot for plotting



zak
05-07-2010, 19:31
Hi
suppose there is a data produced by thinbasic to a file, and we want to plot it, there is a freeware program gnuplot can plot the data either in 2D or 3D perspective.
the site: http://www.gnuplot.info/
the Windows binaries built by Tatsuro Matsuoka can be downloaded from here: (updated today):
http://www.tatsuromatsuoka.com/gnuplot/Eng/winbin/
add to the path c:\gnuplot\binary , the first time you run gnuplot it may take 4 seconds, after that it will run smoothly.
it is better to run gnuplot over a file, but in the two examples below we will use the plotting instructions as parameters ; must be on one line separated by ";".
the first example:
https://sites.google.com/site/perlopengl/gnuplot1.png

Uses "console","OS"
Dim appName As String = "gnuplot.exe -e "
Dim appParameters As String = RawText
"plot sin(x)/x";
"pause mouse keypress";
End RawText
'you can use pause(5) to delay for 5 seconds
appParameters = Trim$(appParameters, Any $CR+$LF+$SPC+$TAB)
appParameters = Remove$(appParameters, Any $CR+$LF)
appName = appName & appParameters
Dim pID As Long

pID = OS_Shell(OS_Environ("COMSPEC") + " /C " & appName ,%OS_WNDSTYLE_NORMAL,%OS_SHELL_SYNC)

PrintL "--Press a key to kill " & appName & "--"
WaitKey
'---Now kill the process using its process id
OS_ProcessKillById(pID)

i have used RawText because i can't give this phrase as string parameter to gnuplot "plot sin(x)/x"; since i can't write it like ""plot sin(x)/x""; is it possible somehow??, any way RawText is handy.

the second example:
https://sites.google.com/site/perlopengl/gnuplot2.png

Uses "console","OS"
Dim appName As String = "gnuplot.exe -e "
Dim appParameters As String = RawText
"set key top left";
"set key box";
"plot [-pi:pi] sin(x) title 'sinusoid' with linespoints pointtype 5, cos(x) t 'cosine' w boxes lt 4";
"pause mouse keypress 'press a key In the active Window to exit'";
End RawText
appParameters = Trim$(appParameters, Any $CR+$LF+$SPC+$TAB)
appParameters = Remove$(appParameters, Any $CR+$LF)
appName = appName & appParameters
Dim pID As Long

pID = OS_Shell(OS_Environ("COMSPEC") + " /C " & appName ,%OS_WNDSTYLE_NORMAL,%OS_SHELL_SYNC)

PrintL "--Press a key to kill " & appName & "--"
WaitKey
'---Now kill the process using its process id
OS_ProcessKillById(pID)

references:
1-excellent tutorial:
http://t16web.lanl.gov/Kawano/gnuplot/index-e.html
2-Visualize your data with gnuplot:
http://www.ibm.com/developerworks/library/l-gnuplot/

3-Gnuplot in Action (August, 2009 | 396 pages):
http://www.manning.com/janert/
any improvements are welcome
regards

ErosOlmi
05-07-2010, 21:29
It seems a great tool!




i have used RawText because i can't give this phrase as string parameter to gnuplot "plot sin(x)/x"; since i can't write it like ""plot sin(x)/x""; is it possible somehow??


Yes you can but you have to inser 2 " for each " inside a string. So something like:

Dim MyString As String = """plot sin(x)/x"";"

ErosOlmi
05-07-2010, 22:46
Is there a way to pass plot script in a file instead directly in command line?

kryton9
06-07-2010, 05:34
That's neat zak.

zak
06-07-2010, 06:48
thanks Eros , kent
yes if the file plotfile.txt contains the text:

plot sin(x)/x
pause(5)

then from command prompt directly : gnuplot plotfile.txt
and from thinbasic:

Uses "console","OS"

Dim pID As Long

pID = OS_Shell(OS_Environ("COMSPEC") + " /C gnuplot.exe plotfile.txt" ,%OS_WNDSTYLE_NORMAL,%OS_SHELL_SYNC)

PrintL "--Press a key to kill the application--"
WaitKey
'---Now kill the process using its process id
OS_ProcessKillById(pID)