
오류 여백이 있는 선 그래프로 플롯하고 다른 png 파일로 출력해야 하는 6개의 파일이 있습니다. 파일 형식은 다음과 같습니다.
초 평균 평균 최소 최대
이 그래프를 자동으로 그리려면 어떻게 해야 합니까? 그래서 bash.sh라는 파일을 실행하면 6개의 파일을 가져와 그래프를 다른 .png
파일로 출력합니다. 제목과 축 레이블도 필요합니다.
답변1
내가 올바르게 이해했다면 이것이 당신이 원하는 것입니다.
for FILE in *; do
gnuplot <<- EOF
set xlabel "Label"
set ylabel "Label2"
set title "Graph title"
set term png
set output "${FILE}.png"
plot "${FILE}" using 1:2:3:4 with errorbars
EOF
done
이는 파일이 모두 현재 디렉터리에 있다고 가정합니다. 위의 내용은 그래프를 생성하는 bash 스크립트입니다. 개인적으로 나는 일반적으로 gnuplot_in
각 파일에 대해 위의 명령을 사용하여 어떤 형식의 스크립트를 사용하여 gnuplot 명령 파일(이라고 부르기)을 작성하고 gnuplot < gnuplot_in
.
예를 들어 Python에서 다음을 수행합니다.
#!/usr/bin/env python3
import glob
commands=open("gnuplot_in", 'w')
print("""set xlabel "Label"
set ylabel "Label2"
set term png""", file=commands)
for datafile in glob.iglob("Your_file_glob_pattern"):
# Here, you can tweak the output png file name.
print('set output "{output}.png"'.format( output=datafile ), file=commands )
print('plot "{file_name}" using 1:2:3:4 with errorbars title "Graph title"'.format( file_name = datafile ), file=commands)
commands.close()
Your_file_glob_pattern
데이터 파일의 이름 지정을 설명하는 항목은 어디에 있습니까 *
? 물론 모듈 *dat
대신 에 glob
사용할 수도 있습니다 . os
실제로는 무엇이든 파일 이름 목록을 생성합니다.
답변2
임시 명령 파일을 사용하는 Bash 솔루션:
echo > gnuplot.in
for FILE in *; do
echo "set xlabel \"Label\"" >> gnuplot.in
echo "set ylabel \"Label2\"" >> gnuplot.in
echo "set term png" >> gnuplot.in
echo "set output \"${FILE}.png\" >> gnuplot.in
echo "plot \"${FILE}\" using 1:2:3:4 with errorbars title \"Graph title\"" >> gnuplot.in
done
gnuplot gnuplot.in
답변3
이것이 도움이 될 수 있습니다.
#set terminal postfile (These commented lines would be used to )
#set output "d1_plot.ps" (generate a postscript file. )
set title "Energy vs. Time for Sample Data"
set xlabel "Time"
set ylabel "Energy"
plot "d1.dat" with lines
pause -1 "Hit any key to continue"
스크립트 파일을 gnuplot filename
.