gpt4 book ai didi

plot - 使用 gnuplot 创建数据文件

转载 作者:行者123 更新时间:2023-12-02 02:44:52 32 4
gpt4 key购买 nike

大家好,我目前正在使用 gnuplot。
我有这个 .csv 文件,我一直用它来绘制一些公式
(例如 plot "filename.csv"u 0:day($0) = $0 )。情节成功了;但是,我想知道 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($1)):(g($1)):(h($1)) w table
unset table

### end of code

编辑:

实际上,为了更灵活地使用输出文件中的数据分隔符(例如逗号或其他),您可以将 plot ... w table 命令更改为类似下面的行。但是,我想,gnuplot 总是会为每一行添加一个前导空格 "" 和一个尾随 TAB \t。但也许这也可以改变。

plot '+' u (sprintf("%g,%g,%g,%g",$1,f($1),g($1),h($1))) w table

结果:

enter image description here

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 你可能是最灵活的,没有前导空格和尾随 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

关于plot - 使用 gnuplot 创建数据文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62981355/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com