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매뉴얼 찾아보면 쉽게 알 수 있습니다.
도움이 되셨으면 좋겠습니다.
'Tcl & Tk > 팁 (Tip)' 카테고리의 다른 글
시간에 따라 변화하는 결과를 plotting하기 (0) | 2025.03.12 |
---|---|
읽어온 데이터를 BLT를 이용해서 2차원 그래프 그리기 (0) | 2025.03.12 |
필요시만 스크롤바 보이게 하기 (0) | 2025.03.06 |
모든 위젯에 툴팁 달기 (0) | 2025.03.06 |
Wish8x를 실행시킬 때 마다 특정 코드를 자동실행 (0) | 2025.03.06 |