使用 gnuplot 创建数据文件
Using gnuplot to create data files
大家好,我目前正在使用 gnuplot。
我有这个 .csv 文件,我一直用它来绘制一些公式
(例如 plot "filename.csv" u 0:day([=10=]) = [=10=]
)。情节成功了;但是,我想知道 gnuplot 中是否有一种方法可以将我的公式的输出也保存为数据文件。
请查看手册或在gnuplot控制台输入help table
。
代码:
### save data as text
reset session
f(x) = x
g(x) = x**2
h(x) = x**3
set xrange[-5:5]
set samples 11
plot f(x) w lp, g(x) w lp, h(x) w lp
set table "myOutput.dat"
plot '+' u 1:(f()):(g()):(h()) w table
unset table
### end of code
编辑:
实际上,为了更灵活地使用输出文件中的数据分隔符(例如逗号或其他),您可以将 plot ... w table
命令更改为类似下面的行。但是,我猜 gnuplot 总是会为每一行添加前导 space " "
和尾随 TAB \t
。但也许这也可以改变。
plot '+' u (sprintf("%g,%g,%g,%g",,f(),g(),h())) w table
结果:
和myOutput.dat
:
-5 -5 25 -125
-4 -4 16 -64
-3 -3 9 -27
-2 -2 4 -8
-1 -1 1 -1
0 0 0 0
1 1 1 1
2 2 4 8
3 3 9 27
4 4 16 64
5 5 25 125
加法:(循环创建数据)
使用 set print
你可能是最灵活的,没有前导 space 和尾随 TAB。
检查手册或在 gnuplot 控制台类型 help set print
.
代码:
### save data as text, independent of range and samples
reset session
f(x) = x
g(x) = x**2
h(x) = x**3
set print "myOutput.dat"
do for [i=-5:5] {
# loop index only takes integers, multiply i with some factor if necessary
print sprintf("%g,%g,%g,%g",i,f(i),g(i),h(i))
}
set print
### end of code
大家好,我目前正在使用 gnuplot。
我有这个 .csv 文件,我一直用它来绘制一些公式
(例如 plot "filename.csv" u 0:day([=10=]) = [=10=]
)。情节成功了;但是,我想知道 gnuplot 中是否有一种方法可以将我的公式的输出也保存为数据文件。
请查看手册或在gnuplot控制台输入help table
。
代码:
### save data as text
reset session
f(x) = x
g(x) = x**2
h(x) = x**3
set xrange[-5:5]
set samples 11
plot f(x) w lp, g(x) w lp, h(x) w lp
set table "myOutput.dat"
plot '+' u 1:(f()):(g()):(h()) w table
unset table
### end of code
编辑:
实际上,为了更灵活地使用输出文件中的数据分隔符(例如逗号或其他),您可以将 plot ... w table
命令更改为类似下面的行。但是,我猜 gnuplot 总是会为每一行添加前导 space " "
和尾随 TAB \t
。但也许这也可以改变。
plot '+' u (sprintf("%g,%g,%g,%g",,f(),g(),h())) w table
结果:
和myOutput.dat
:
-5 -5 25 -125
-4 -4 16 -64
-3 -3 9 -27
-2 -2 4 -8
-1 -1 1 -1
0 0 0 0
1 1 1 1
2 2 4 8
3 3 9 27
4 4 16 64
5 5 25 125
加法:(循环创建数据)
使用 set print
你可能是最灵活的,没有前导 space 和尾随 TAB。
检查手册或在 gnuplot 控制台类型 help set print
.
代码:
### save data as text, independent of range and samples
reset session
f(x) = x
g(x) = x**2
h(x) = x**3
set print "myOutput.dat"
do for [i=-5:5] {
# loop index only takes integers, multiply i with some factor if necessary
print sprintf("%g,%g,%g,%g",i,f(i),g(i),h(i))
}
set print
### end of code