来自多个输入数据文件的2D图

时间:2017-10-14 09:52:43

标签: gnuplot

我的代码返回1000 snapshot_XXXX.dat个文件(XXXX = 0001,0002,...)。它们是两列数据文件,用于拍摄我在特定时间运行的系统。我想按照它们的创建顺序混合它们来构建一个2D图(或热图),它将显示我随着时间的推移量的变化。

如何使用gnuplot执行此操作?

1 个答案:

答案 0 :(得分:0)

假设您希望时间轴从下到上,您可以尝试以下方法:

n=4  # Number of snapshots

set palette defined (0 "white", 1 "red")
unset key
set style fill solid

set ylabel "Snapshot/Time"
set yrange [0.5:n+0.5]
set ytics 1

# This functions gives the name of the snapshot file
snapshot(i) = sprintf("snapshot_%04d.dat", i)

# Plot all snapshot files.
# - "with boxes" fakes the heat map
# - "linecolor palette" takes the third column in the "using" 
#   instruction which is the second column in the datafiles
# Plot from top to bottom because each boxplot overlays the previous ones.

plot for [i=1:n] snapshot(n+1-i) using 1:(n+1.5-i):2 with boxes linecolor palette

此示例数据

snapshot_0001.dat  snapshot_0002.dat  snapshot_0003.dat  snapshot_0004.dat
1.0 0.0            1.0 0.0            1.0 0.0            1.0 0.0
1.5 0.0            1.5 0.0            1.5 0.0            1.5 0.0
2.0 0.5            2.0 0.7            2.0 0.7            2.0 0.7
2.5 1.0            2.5 1.5            2.5 1.5            2.5 1.5
3.0 0.5            3.0 0.7            3.0 1.1            3.0 1.5
3.5 0.0            3.5 0.0            3.5 0.7            3.5 1.1
4.0 0.0            4.0 0.0            4.0 0.0            4.0 0.7
4.5 0.0            4.5 0.0            4.5 0.0            4.5 0.0
5.0 0.0            5.0 0.0            5.0 0.0            5.0 0.0

产生此图像(使用Gnuplot 5.0测试):

evolution with time from bottom to top

如果您想从上到下,可以更改绘图的顺序。如果你想从左到右,也许this可以提供帮助(未经测试)。