用线gnuplot绘制矩阵

时间:2014-05-19 20:52:38

标签: matrix gnuplot

我正在制作图表,但我想使用线而不是点。

使用线条样式,所有点都连接在一起,图形具有网络外观,这是我不想要的。

set grid 
set ticslevel 0.1 
set samples 51, 51 
set isosamples 20, 20 
set border 1+2+4+8
unset key
splot 'matrix.dat' matrix

数据到矩阵图的一部分

0.261   0.665   0.225   0.382   0.255   0.574   0.356
0.338   0.845   0.0363  0.167   0.727   0.0805  0.764
0.225   0.196   0.107   0.153   0.347   0.338   0.168
0.157   0.443   0.0671  0.135   0.312   0.408   0.362
0.151   0.281   0.0572  0.103   0.309   0.49    0.242
0.12    0.336   0.0604  0.173   0.19    0.395   0.153
0.119   0.173   0.0336  0.145   0.156   0.219   0.177
0.123   0.0452  0.0165  0.149   0.0932  0.0663  0.133
0.123   0.0741  0.00373 0.136   0.0346  0.485   0.131
0.111   0.241   0.0124  0.105   0.0127  1.01    0.122
0.096   0.475   0.0194  0.0569  0.0284  1.67    0.102
0.0777  0.773   0.0175  0.00929 0.0375  2.42    0.0831
0.059   1.11    0.0123  0.0322  0.0408  3.23    0.0635
0.0438  1.48    6.44E-4 0.0659  0.0265  4.07    0.0445
0.0349  1.92    0.0192  0.078   0.00585 4.92    0.0254
0.0392  2.42    0.0446  0.0632  0.0306  5.73    0.00774
0.0518  2.97    0.0745  0.031   0.0729  6.46    0.00716

Model Graphics

2 个答案:

答案 0 :(得分:2)

这不能自动完成。您必须确定矩阵的行和列。首先,要获得行数,请使用

stats 'matrix.dat' using 1 nooutput
rows = STATS_records

对于列数,请使用

stats 'matrix.dat' matrix nooutput
cols = STATS_records/rows

现在绘制每一行

unset key
splot for [i=0:cols-1] 'matrix.dat' matrix every ::i::i lt 1 with lines

结果(用4.6.4)是:

enter image description here

答案 1 :(得分:0)

我认为Christoph的解决方案正是您所需要的,但为了明确这一点,通过提供矩阵并单独使用splot matrix将生成网格。

因此,您需要指定具有完整X,Y和Z向量的线,然后使用带有线/线点的splot绘制它们。我在下面添加了一个示例,以防它可能对其他人有所帮助。

您按如下方式排列数据文件: 10 1 0.261 2 0.665 3 0.225 4 0.382 5 0.255 6 0.574 7 0.356 20 1 0.338 2 0.845 3 0.0363 4 0.167 5 0.727 6 0.0805 7 0.764 30 1 0.225 2 0.196 3 0.107 4 0.153 5 0.347 6 0.338 7 0.168 40 1 0.157 2 0.443 3 0.0671 4 0.135 5 0.312 6 0.408 7 0.362

然后绘制如下:

set grid 
set ticslevel 0.1 
#set samples 51, 51 
#set isosamples 20, 20 
#set border 1+2+4+8
unset key
splot 'matrix.dat' using 1:2:3 with linespoints, \
'matrix.dat'  using 1:4:5 with linespoints, \
'matrix.dat'  using 1:6:7 with linespoints, \
'matrix.dat'  using 1:8:9 with linespoints, \
'matrix.dat'  using 1:10:11 with linespoints, \
'matrix.dat'  using 1:12:13 with linespoints, \
'matrix.dat'  using 1:14:15 with linespoints

结果图

enter image description here