0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

シェルを使ってcsvファイルからgnuplotでグラフを作成する

Posted at

プログラム例

#!/bin/sh

loop=true

while [ "$loop" = true ]
do

read -p "入力ファイル : " input_file
read -p "出力ファイル : " output_file

if [ ! -f "$input_file.csv" ]; then
  echo "入力ファイルが見つかりません。"
  continue
fi

read -p "x軸のプロット範囲 ex.始値 増分 終値 : " x_start x_inc x_finish
read -p "y軸のプロット範囲 ex.始値 増分 終値 : " y_start y_inc y_finish

gnuplot <<EOF
set encoding cp932
set terminal pngcairo
set datafile separator ","
set output "$output_file.png"

set tics font "Times New Roman, 12"
set xlabel font "Times New Roman, 12"
set ylabel font "Times New Roman, 12"
set key font "Times New Roman, 12"
set key right

set xlabel "x"
set xtics $x_start, $x_inc, $x_finish
set xrange [$x_start:$x_finish]

set ylabel "y"
set ytics $y_start, $y_inc, $y_finish
set yrange [$y_start:$y_finish]
plot "$input_file.csv" using \$1:\$2 title "" w l lc rgb "black"
EOF

read -p "保存しますか [y/n] : " save_file

if [ "$save_file" = "n" ]; then
    rm "$output_file.png"
fi

read -p "終了しますか [y/n] : " finish

if [ "$finish" = "y" ]; then
    loop=false
fi

done

注意点

通常,csvファイルの列指定の際に\はいりませんが,シェルスクリプトの場合,シェルとgnuplotの変数を区別する必要があるため\が必要になります.それ以外の書き方は同じです.

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?