无法在Gnuplot中绘制矩阵

时间:2016-02-04 19:42:33

标签: matrix plot gnuplot

我有一个1s和0的矩阵保存在文件中。它看起来像这样:

    0 0 0 0 0 0 0 0 0 0 
    0 0 0 0 0 0 0 0 0 0 
    0 0 0 0 0 0 0 0 0 1 
    0 0 0 0 0 0 0 0 0 0 
    0 0 0 0 0 0 0 1 1 0 
    0 0 0 0 0 1 1 0 0 0 
    1 1 1 1 1 0 0 0 0 0 
    0 0 0 0 0 0 0 0 0 0 
    0 0 0 0 0 0 0 0 0 0 
    0 0 0 0 0 0 0 0 0 0 

我试图使用命令在gnuplot中绘图:

    plot 'data.rtf' matrix with image

但是当我这样做时,我收到一个错误:

    warning: matrix contains missing or undefined values
    Matrix does not represent a grid

我想我应该得到一个图像,其中0是空白,1是黑色空间。我是gnuplot的新手,所以我不知道可能出现什么问题,也不知道我是否正确地使用它。我将不胜感激任何帮助。感谢。

2 个答案:

答案 0 :(得分:3)

您的文件是rtf(富文本格式)文件,这是一种标记语言格式,gnuplot无法理解。您需要在文本编辑器(而不是文字处理器)中创建文件才能使用它。

您提供的文件如下:

{\rtf1\ansi\ansicpg1250\cocoartf1404\cocoasubrtf340
{\fonttbl\f0\fnil\fcharset0 Menlo-Regular;}
{\colortbl;\red255\green255\blue255;}
\paperw11900\paperh16840\margl1440\margr1440\vieww10800\viewh8400\viewkind0
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\pardirnatural\partightenfactor0

\f0\fs22 \cf0 \CocoaLigature0 0 0 0 0 0 0 0 0 0 0\
0 0 0 0 0 0 0 0 0 0\
0 0 0 0 0 0 0 0 0 1\
0 0 0 0 0 0 0 0 0 0\
0 0 0 0 0 0 0 1 1 0\
0 0 0 0 0 1 1 0 0 0\
1 1 1 1 1 0 0 0 0 0\
0 0 0 0 0 0 0 0 0 0\
0 0 0 0 0 0 0 0 0 0\
0 0 0 0 0 0 0 0 0 0

请注意,它以一堆标记文本开头。 Gnuplot旨在处理文本文件而不是格式化文本或二进制文件(除了一些有限的例外)。

创建包含您设计矩阵的文本文件就可以了。

答案 1 :(得分:0)

颜色图是类似于表面的图,因此您必须使用splot而不是plot

set pm3d map
set palette gray
splot 'test.txt' matrix w image