Gnuplot用图像绘制二维矩阵,想要为每个单元格绘制边框 [英] Gnuplot plot 2D matrix with image, want to draw borders for each cell
问题描述
我想用gnuplot绘制18x18矩阵.这是我的代码:
I want to plot a 18x18 matrix with gnuplot. Here is my codes:
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
然后我得到了一个像这样的无花果:
Then I got a fig like this:
现在,我想为每个单元格添加边框,如下所示:
Now I would like to add borders to each cell, which will look like this:
谢谢.
推荐答案
对于您的情况,您可以设置一个次要tic,然后将其放置在两个像素之间的边界上,并在其上绘制网格:
For your case you can set one minor tic, which then lies on the border between two pixels, and draw a grid on them:
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
还将抽芯杆放在前面.为避免这种情况,您可以将tic缩放至0
.对于次要抽动,您必须使用非常小的数字,0
将忽略次要抽动上的网格线.
Note, that set grid front
also brings the tics to the front. To avoid that you can scale the tics to 0
. For the minor tics you must use a very small number, 0
would omit the grid lines on the minor tics.
4.6.3的结果是:
The result with 4.6.3 is:
为了独立控制网格线和tic标签,您可以使用未使用的x2
和y2
绘制网格(受
In order to control the grid lines and tic labels independently, you can use the unused x2
and y2
to draw the grid (inspired by an answer to 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
从数据文件中提取信息.
With gnuplot
version 4.6, this requires setting explicit ranges, so that the x
and x2
(unused!) are equal. The information might be extracted with stats
from the data file.
使用版本5可以使用set link
.而不是所有的set *range
东西.您可以使用:
Using version 5 allows you to use set link
. Instead of all the set *range
stuff. You could use:
set autoscale fix
set link x
set link y
结果:
这篇关于Gnuplot用图像绘制二维矩阵,想要为每个单元格绘制边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!