plot - Gnuplot 用图像绘制二维矩阵,想要为每个单元格绘制边框

标签 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

谢谢。

最佳答案

对于您的情况,您可以设置一个小抽动,然后它位于两个像素之间的边界上,并在其上绘制一个网格:

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

编辑:为了独立控制网格线和tic标签,您可以使用未使用的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

关于plot - Gnuplot 用图像绘制二维矩阵,想要为每个单元格绘制边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19201484/

相关文章:

lisp - 使用 Common Lisp 和 Gnuplot 从 emacs 顺序绘制数据

Gnuplot 对相同的 x 值求和 y 值

pdf-generation - gnuplot:无法识别的终端选项

Python matplotlib 线框失真

r - 使用掩码后 NA 值的颜色

image - 在 MATLAB 中使用 imshow 方法显示图像标题

python - 创建 for 循环以使用 Seaborn 为 DataFrame 的各个列绘制直方图

gnuplot - 在基于时间的折线图上绘制 bool 值

python - Matplotlib 3D 条形图 : axis issue

gnuplot : using a logarithmic axis for a histogram