使用gnuplot创建数据文件 [英] Using gnuplot to create data files

查看:147
本文介绍了使用gnuplot创建数据文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我目前正在使用gnuplot.
我已经使用了这个.csv文件来绘制一些公式
(例如plot "filename.csv" u 0:day($0) = $0).情节解决了;但是,我想知道gnuplot中是否也有一种方法可以将公式的输出另存为数据文件.

Hey guys I am currently working with gnuplot.
I have this .csv file which I have been using to plot some formulas
(eg plot "filename.csv" u 0:day($0) = $0 ). The plots worked out; however, I was wondering if there was a way within gnuplot to save the output of my formulas as a data file too.

推荐答案

请查看手册或在gnuplot控制台中键入help table.

Please check the manual or in the gnuplot console type 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.但这也许也可以更改.

Actually, to be more flexible with data separators (e.g. comma or whatever) in the output file, you could change the plot ... w table command to something like the line below. However, I guess, gnuplot will always add a leading space " " and a trailing TAB \t for each line. But maybe this can also be changed.

plot '+' u (sprintf("%g,%g,%g,%g",$1,f($1),g($1),h($1))) 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

添加 :(循环创建数据)

Addition: (creating data in a loop)

使用set print,您可能是最灵活的,没有前导空格和结尾的TAB. 查看手册或在gnuplot控制台中键入help set print.

With set print you are probably the most flexible, no leading space and trailing TAB. Check the manual or in gnuplot console type 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创建数据文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆