我想用 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
然后我得到了一个这样的无花果:
现在我想为每个单元格添加边框,如下所示:
谢谢。
最佳答案
对于您的情况,您可以设置一个小抽动,然后它位于两个像素之间的边界上,并在其上绘制一个网格:
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 的结果是:
编辑:为了独立控制网格线和tic标签,您可以使用未使用的
x2
和 y2
绘制网格(灵感来自对 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 版,这需要设置明确的范围,以便 x
和 x2
(未使用!)是平等的。该信息可能通过 stats
提取从数据文件。使用第 5 版允许您使用
set link
.而不是所有的 set *range
东西。你可以使用:set autoscale fix
set link x
set link y
结果:
关于plot - Gnuplot 用图像绘制二维矩阵,想要为每个单元格绘制边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19201484/