블로그 이미지
closer_

Rss feed Tistory
일상 2009. 11. 12. 16:49

Visual C++ 에서 GnuPlot 사용하는 방법

한글판: http://youngcho.tistory.com/category/Programming

 

출처: http://www.quantcode.com/modules/smartfaq/faq.php?faqid=5

How do I call GnuPlot from C++ in Windows XP?

Requested and Answered by Malbury on 13-Jan-2007 21:34 (7747 reads)

 

1.If there is no copy of wgnuplot.exe present on your box do either of the following:
1a. Download and install Gnuplot from gnuplot
1b. Download and Install Octave for Windows from sourceforge (It comes with Gnuplot.exe in bin directory)

Note : I found it more convenient to have Octave because the plotting tasks are very simple to use from Octave, and the generated Gnuplot commands can be helpful to create a command text file for C++ use.

2.Note location of directory containing wgnuplot.exe and add it to the system path.

3.Verify that the gnuplot window launches properly when the command "wgnuplot" is typed into the MS DOS command prompt.

4.Write and save a datafile from C++ output program eg., myplotdata.dat (see below example)

5.Write and save a command text file containg plot commands and syntax compatible with Gnuplot. eg.,mycmdfile.txt. Remember to use command "pause -1" at the last otherwise you will not be able to see the window as it will disappear fast. (see below example)

6.Use system("wgnuplot.exe c:\\mycmdfile.txt") in C++ to run gnuplot and display the graph

Following is example of myplotdata.dat file:

0.000000 0.000000
0.000000 228.000000
0.068750 228.000000
0.068750 0.000000
0.068750 15.000000
0.137500 15.000000
0.137500 0.000000
0.137500 0.000000
0.206250 0.000000
0.206250 0.000000
0.206250 1.000000
0.275000 1.000000
0.275000 0.000000
0.275000 0.000000
0.343750 0.000000
0.343750 0.000000
0.343750 9.000000


following is example of mycmdfile.txt which plots bar graph:
set data style lines
set nologscale
set nopolar
pl 'C:\myplotdata.dat' u 1:2 t 'line 1'
pause -1


For an example of how this is done, refer the function PlotHistogram in the program CDO Square Loss distribution using Gaussian Copula


,
TOTAL TODAY