2017-02-24 23 views
2

我有xrange的麻烦。当我把'set autoscale xfix'图像确定,但没有信息轴。当我把xrange [-1:1]我得到信息好,但图像是损害。第二个麻烦是翻转图像。在我存储在文件左上角的数据是-1,图像是+1,为什么?与图像和xrange的情节矩阵的麻烦

我的数据是:

-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 

test image

我的图像是-1到1步骤0.5 如果我添加集x范围[-1: 1]并设置yrange [-1:1]我得到 ugly image

$ gnuplot -V 
gnuplot 5.0 patchlevel 3 

回答

2

问题是你的数据文件被解释为统一的matrix。在这种情况下:

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_records中。功能fn然后在[-1:1]上重新调整范围[0:STATS_records-1]。此外,x/y-标签会自动调整。

+0

是否可以读取最大范围数据?有时我使用更多的数据是可能写入自动功能? Chodzi o to,żejeślichce zwiększąrozdzielczościąwygenerowaćobrazemmuszęzmieniacfunkcjęf()asiętozrobićjakośautomatycznie。 –

+1

@EliaszŁukasz我已经包含了一般方阵的扩展。该脚本首先找出矩阵的大小,然后调整缩放以及抽动。 – ewcz

+0

太棒了。非常感谢 –