コンテンツにスキップ

Gnuplot

WSL2 で普通に使える。

インストール

1
$ sudo apt install gnuplot

基本

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# 起動する
$ gnuplot

# 数式を入力する
gnuplot> plot sin(x) / x

# x軸のレンジを指定する
gnuplot> set xrange[-20:20]

# y軸のレンジを指定する
gnuplot> set yrange[-2:2]

# x軸のラベルを指定する(ダブルクォーテーション必須)
gnuplot> set xlabel "x"

# y軸のラベルを指定する(ダブルクォーテーション必須)
gnuplot> set ylabel "y"

# グラフのタイトルを指定する(ダブルクォーテーション必須)
gnuplot> set title "sinc"

# 補助軸を表示する
gnuplot> set grid

# 描画する
gnuplot> replot

# 終了する
gnuplot> exit

$

三角関数

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
$ gnuplot

# 複数のグラフをプロットする
gnuplot> plot sin(x) title "sin(x)", cos(x) title "cos(x)", tan(x) title "tan(x)"

# 横軸レンジを設定する
gnuplot> set xrange[-2*pi:2*pi]

# 縦軸レンジを設定する
gnuplot> set yrange[-1:1]

# 横軸のラベルを設定する
gnuplot> set xlabel "x"

# 縦軸のラベルを設定する
gnuplot> set ylabel "y"

# タイトルを設定する
gnuplot> set title "sin cos tan"

# 横軸のフォーマットを指定する(%Pで値を円周率の倍数表記にして、πの文字を{/Symbol p}で表示する)
gnuplot> set format x "%2.1P{/Symbol p}"

# 横軸の目盛りをpi/2単位にする
gnuplot> set xtics pi/2

# 横軸の目盛りをさらに何分割するか指定する(1で分割しない)
gnuplot> set mxtics 1

# 補助線を表示する(非表示はunset grid)
gnuplot> set grid

# 再描画する
gnuplot> replot

関数いろいろ

関数 表記
\(\sqrt{x}\) sqrt(x)
\(\|x\|\) abs(x)
\(\mathrm{sin}{x}\) sin(x)
\(\mathrm{cos}{x}\) cos(x)
\(\mathrm{tan}{x}\) tan(x)
\(e^x\) exp(x)
\(10^x\) 10**x
\(\mathrm{log}_e{x}\) log(x)
\(\mathrm{log}_{10}{x}\) log10(x)