我有一个包含4个数字(最小值,最大值,平均值,标准推导值)的文件,我想用gnuplot绘制它.
样品:
24 31 29.0909 2.57451
12 31 27.2727 5.24129
14 31 26.1818 5.04197
22 31 27.7273 3.13603
22 31 28.1818 2.88627
Run Code Online (Sandbox Code Playgroud)
如果我有一个列有4个文件,那么我可以这样做:
gnuplot "file1.txt" with lines, "file2.txt" with lines, "file3.txt" with lines, "file4.txt" with lines
Run Code Online (Sandbox Code Playgroud)
它将绘制4条曲线.我不关心x轴,它应该只是一个恒定的增量.
我怎么能请情节?我似乎无法找到一种方法,有4条曲线,1个文件有4列,只有一个不断递增的x值.
谢谢.
Tho*_*hor 78
您可以绘制同一文件的不同列,如下所示:
plot 'file' using 0:1 with lines, '' using 0:2 with lines ...
Run Code Online (Sandbox Code Playgroud)
(...指继续).关于这种表示法的几点说明:using指定要绘制的列,即第一个using语句中的第0列和第1列,第0列是伪列,转换为数据文件中的当前行号.请注意,如果只使用一个参数using(例如using n)它对应于说using 0:n(感谢指出mgilson).
如果您的Gnuplot版本足够新,您可以使用for循环绘制所有4列:
set key outside
plot for [col=1:4] 'file' using 0:col with lines
Run Code Online (Sandbox Code Playgroud)
结果:

如果标题位于数据文件中,则Gnuplot可以使用列标题,例如:
min max mean std
24 31 29.0909 2.57451
12 31 27.2727 5.24129
14 31 26.1818 5.04197
22 31 27.7273 3.13603
22 31 28.1818 2.88627
Run Code Online (Sandbox Code Playgroud)
和
set key outside
plot for [col=1:4] 'file' using 0:col with lines title columnheader
Run Code Online (Sandbox Code Playgroud)
结果是:

j_s*_*j_s 11
只是要补充一点,您可以将for循环中的增量指定为第三个参数.如果要绘制每个第n列,这将非常有用.
plot for [col=START:END:INC] 'file' using col with lines
Run Code Online (Sandbox Code Playgroud)
在这种情况下,它无论如何都会改变:
plot for [col=1:4:1] 'file' using col with lines
Run Code Online (Sandbox Code Playgroud)