Gnuplot绘制带图像的2D矩阵,想要为每个单元格绘制边框

时间:2013-10-05 18:54:42

标签: plot gnuplot

我想用gnuplot绘制一个18x18矩阵。这是我的代码:

set size ratio 1
set palette gray negative
set xrange[-0.5:17.5]
set yrange[-0.5:17.5]
set cbrange[-0.2:0.8]
set xtics 0,1,17
set ytics 0,1,17
set xtics offset -0.5,0
set title "Resolusition Matrix for E"
plot "Mat" matrix w image noti

然后我得到了这样的无花果:

enter image description here

现在我想为每个单元格添加边框,如下所示:

enter image description here

谢谢。

1 个答案:

答案 0 :(得分:14)

对于你的情况,你可以设置一个小的tic,然后它位于两个像素之间的边界上,并在它们上画一个网格:

set size ratio 1
set palette gray negative
set autoscale xfix
set autoscale yfix
set xtics 1
set ytics 1
set title "Resolution Matrix for E"

set tics scale 0,0.001
set mxtics 2
set mytics 2
set grid front mxtics mytics lw 1.5 lt -1 lc rgb 'white'
plot "Mat" matrix w image noti

请注意,set grid front也会将抽搐带到前面。为避免这种情况,您可以将抽搐缩放到0。对于次要抽搐,您必须使用非常小的数字,0将省略次要抽搐上的网格线。

4.6.3的结果是:

enter image description here

编辑:为了独立控制网格线和标签,您可以使用未使用的x2y2绘制网格(灵感来自How do I draw a vertical line in gnuplot?的答案):

set size ratio 1
set palette gray negative
# grid lines
set x2tics 1 format '' scale 0,0.001
set y2tics 1 format '' scale 0,0.001
set mx2tics 2
set my2tics 2

# labeling
set xtics 5 out nomirror
set ytics 5 out nomirror

set grid front mx2tics my2tics lw 1.5 lt -1 lc rgb 'white'

set xrange[-0.5:39.5]
set yrange[-0.5:39.5]
set x2range[-0.5:39.5]
set y2range[-0.5:39.5]

plot "Mat" matrix w image notitle

使用gnuplot版本4.6,这需要设置显式范围,以便xx2(未使用!)相等。可以使用数据文件中的stats提取信息。

使用版本5可以使用set link。而不是所有set *range的东西。你可以使用:

set autoscale fix
set link x
set link y

结果:

enter image description here