쉘 스크립트를 사용하여 gnuplot에서 명령을 실행하는 방법은 무엇입니까? 명령을 실행 한 다음 종료하라는 스크립트를

내가하고 싶은 것은 먼저 프로그램을 시작한 다음 많은 명령을 실행 한 다음 종료하라는 스크립트를 작성하는 것입니다. 예를 들어 봅시다.

이 스크립트를 작성했는데 myscript.sh원하는 방식으로 작동하지 않습니다. gnuplot을 실행하고 종료 될 때까지 기다렸다가 다른 명령을 실행하면됩니다. 분명히 오류가 발생합니다.

#!/bin/bash
gnuplot
plot sin(x)
pause -1
quit

내가하려는 일이 분명하다고 생각합니다. 그렇지 않은 경우 의견에 알려주십시오.



답변

에서 man gnuplot또는 온라인 맨 페이지 :

   -p,  --persist  lets  plot  windows  survive after main gnuplot program
   exits.

   -e "command list" executes the requested commands  before  loading  the
   next input file.

따라서 아마도 다음과 같은 명령을 실행하고 싶을 것입니다.

gnuplot -e "plot sin(x); pause -1"

내가 제안했지만 그다지 유용하지 않은 다른 변형은 다음과 같습니다.

gnuplot -p -e "plot sin(x); pause -1"
gnuplot -e "plot sin(x)"
gnuplot -p -e "plot sin(x)"


답변

한 가지 방법은 다음과 -persist같습니다.

#!/usr/bin/gnuplot -persist
set title "Walt pedometer" font ",14" textcolor rgbcolor "royalblue"
set timefmt "%y/%m/%d"
set xdata time
set pointsize 1
set terminal wxt  enhanced title "Walt's steps " persist raise
plot "/home/walt/var/Pedometer" using 1:2 with linespoints

데이터를 전처리해야하는 다른 방법은 Bash를 사용하는 것입니다 Here Document(참조 man bash).

#!/bin/bash
minval=0    # the result of some (omitted) calculation
maxval=4219   # ditto
gnuplot -persist <<-EOFMarker
    set title "Walt pedometer" font ",14" textcolor rgbcolor "royalblue"
    set timefmt "%y/%m/%d"
    set yrange $minval:$maxval
    set xdata time
    set pointsize 1
    set terminal wxt  enhanced title "Walt's steps " persist raise
    plot "/home/walt/var/Pedometer" using 1:2 with linespoints
EOFMarker
# rest of script, after gnuplot exits


답변

에서 설명하고있는 바와 같이 man페이지 , gnuplot소위의 명령 파일에서 입력을 기대 배치 세션 . 예를 들어 줄 plot sin(x)을 파일에 쓴 myplot다음 실행할 수 gnuplot myplot있습니다.

스크립트와 마찬가지로 명령 파일을 생략하면 대화식 세션이 표시 됩니다.


답변

언급 된 here-doc 방법은 Gnuplot 및 기타 여러 프로그램에서도 매우 유용합니다. here-doc의 Gnuplot 명령 내에서 쉘 변수를 사용하여 쉘 스크립트 명령 행의 입력으로 플롯을 매개 변수화 할 수 있습니다. 신중하게 설정하면 광대 한 “빅 데이터”팀에서 줄거리를 대량 생산할 수 있습니다. 필자는이 방법을 사용하여 수백 개의 구조 역학 유한 분석 실행에서 PLOT 당 20,000 ~ 80,000 포인트로 일관된 모양의 산점도를 생성했습니다. 매우 강력한 방법입니다.


답변

이것은 도움이 될 수 있습니다

{#set terminal postfile             
{#set output  "d1_plot.ps"        
set title "Energy vs. Time for Sample Data"    
set xlabel "Time"    
set ylabel "Energy"    
plot "d1.dat" with lines   
pause -1 "Hit Enter to continue"

자세한 내용은 여기를 클릭하십시오


답변