Tcl & Tk/팁 (Tip)
Gnuplot + Tcl/Tk
티클러
2025. 3. 12. 09:47
zaskateam 님이 제공해 주신 팁입니다.
Gnuplot(http://www.gnuplot.info)은 간단하면서도 파워풀한 그래픽 툴입니다.
물론 오픈 소스 프로그램입니다.
Tcl/Tk canvas에 gnuplot을 이용해 그래프 그리는 방법을 간단히 소개합니다.
Gnuplot홈페이지에 가시면 데모들을 확인할 수 있습니다.
이 방법 찾느라 오전부터 계속 삽질하다 겨우 찾았습니다.
정말 간단한 그림만 데모로 올려놓습니다.
1차원 그래프 그리기
set gpexe ./gp373w32/pgnuplot.exe
set outfile ./resultat.tk
set gp [open "|$gpexe" r+]
puts $gp "set term tk"
puts $gp "set data style lines"
puts $gp "set grid"
puts $gp "set xlabel 'Cycle'"
puts $gp "set ylabel 'Potential (V)'"
puts $gp "set output '$outfile'"
puts $gp "plot 'output.txt' u 1:2 t 'Vw'"
close $gp
pack [canvas .c -background white -width 800 -height 644]
source $outfile
gnuplot .c
2차원 그래프 그리기
set gpexe ./gp373w32/pgnuplot.exe
set outfile ./resultat.tk
set gp [open "|$gpexe" r+]
puts $gp "set term tk"
puts $gp "set parametric"
puts $gp "set data style line"
puts $gp "set cntrparam level auto 10"
puts $gp "set hidden3d"
puts $gp "set bmargin 0"
puts $gp "set contour"
puts $gp "set view 60,120"
puts $gp "set xlabel 'r (cm)'"
puts $gp "set ylabel 'z (cm)'"
puts $gp "set zlabel 'Te (eV)'"
puts $gp "set title 'Te (eV)'"
puts $gp "set output '$outfile'"
puts $gp "splot 'te.txt' t 'Te'"
close $gp
pack [canvas .c -background white -width 800 -height 644]
source $outfile
gnuplot .c
set 이후의 명령어는 gnuplot매뉴얼 찾아보면 쉽게 알 수 있습니다.
도움이 되셨으면 좋겠습니다.