Matrix 带有图像和X范围的打印矩阵出现故障
我的xrange有问题。当我放置“设置自动缩放xfix”时,图像正常,但信息轴不正常。当我放置xrange[-1:1]时,我得到的信息正常,但图像受损。第二个问题是翻转图像。在我的数据存储在文件左上角是-1的图像上是+1,为什么 我的数据是:Matrix 带有图像和X范围的打印矩阵出现故障,matrix,gnuplot,Matrix,Gnuplot,我的xrange有问题。当我放置“设置自动缩放xfix”时,图像正常,但信息轴不正常。当我放置xrange[-1:1]时,我得到的信息正常,但图像受损。第二个问题是翻转图像。在我的数据存储在文件左上角是-1的图像上是+1,为什么 我的数据是: -0.999770 -0.998743 0.946455 0.999678 0.999777 -0.699447 -0.999784 -0.999565 -0.076214 0.999467 0.999921 -0.717181 -0.999
-0.999770 -0.998743 0.946455 0.999678 0.999777
-0.699447 -0.999784 -0.999565 -0.076214 0.999467
0.999921 -0.717181 -0.999790 -0.999734 -0.959481
0.999943 0.999920 -0.733798 -0.999793 -0.999786
0.999943 0.999943 0.999920 -0.749453 -0.999794
我的代码是:
set terminal png transparent enhanced font "arial,10" fontscale 1.0 size 600, 400
set output 'out.png'
set xtics 0.25
set ytics 0.25
set xrange [-1:1]
set yrange [-1:1]
set cbrange [-1:1]
plot 'data.txt' matrix with image
我的图像是-1到1步0.5
如果我加上set xrange[-1:1]和set yrange[-1:1],我得到
问题是您的数据文件被解释为一个统一的
矩阵
。在这种情况下:
gnuplot> help matrix
Gnuplot can interpret matrix data input in two different ways.
The first of these assumes a uniform grid of x and y coordinates and assigns
each value in the input matrix to one element M[i,j] of this uniform grid.
The assigned x coordinates are the integers [0:NCOLS-1].
The assigned y coordinates are the integers [0:NROWS-1].
因此,这意味着文件第一行中的数据点将y
-坐标设置为0,第二行1等。但是,由于默认情况下y
-轴指向上方,因此结果图像会翻转。此外,这些点定义了绘图中基本颜色方块/方框的中心。这就是“有效x/y范围”在您的情况下的方式[-0.5:4.5]
要“固定”y轴,可以使用
set yr [] reverse
此处,[]
指定轴仍处于自动缩放状态
最后,要将图像从[0,4]重新缩放到[-1,1]范围,可以使用:
fn(x) = x/2. - 1
plot 'data.txt' matrix u (fn($1)):(fn($2)):3 w image
因此,总的来说:
set terminal png transparent enhanced font "arial,10" fontscale 1.0 size 600, 400
set output 'out.png'
set xtics 0.25
set ytics 0.25
set xrange [-1:1]
set yrange [-1:1] reverse
set cbrange [-1:1]
fn(x)=x/2-1
plot 'data.txt' matrix u (fn($1)):(fn($2)):3 w image
编辑:
还可以修改上面的脚本,以处理先验未知大小的矩阵:
set terminal png transparent enhanced font "arial,10" fontscale 1.0 size 600, 400
set output 'out.png'
set xrange [-1:1]
set yrange [-1:1] reverse
set cbrange [-1:1]
fName = 'data.txt'
stats fName nooutput
N = STATS_records - 1
set xtics 1./N
set ytics 1./N
fn(x)=(2*x/N)-1
plot fName matrix u (fn($1)):(fn($2)):3 w image
这里,
stats
命令首先扫描文件,并将记录数存储到一个特殊变量stats\u records
中。功能fn
然后在[-1:1]
上重新缩放范围[0:STATS\u records-1]
。此外,x/y-
tics会自动调整。是否可以读取最大范围数据?有时我用更多的数据可以写自动功能吗?zrobićjakośautomatycznie的Chodzi o to,śe jeśli chce z większąrozedzielczościąwyrogenewaćobrazem muszęzmieniac funkcjęf()a może dało。@elaszŁukasz I包含了对一般平方矩阵的扩展。脚本首先找出矩阵的大小,然后调整缩放比例以及TIC。
set terminal png transparent enhanced font "arial,10" fontscale 1.0 size 600, 400
set output 'out.png'
set xrange [-1:1]
set yrange [-1:1] reverse
set cbrange [-1:1]
fName = 'data.txt'
stats fName nooutput
N = STATS_records - 1
set xtics 1./N
set ytics 1./N
fn(x)=(2*x/N)-1
plot fName matrix u (fn($1)):(fn($2)):3 w image